How to run a JAR file in Java?

0 votes
I have created a JAR file. But I am not able to run it. How can I execute it?
Jun 1, 2018 in Java by Sushmita
• 6,820 points
170 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

The command given below will help you to run the JAR file.

java -classpath Predit.jar your.package.name.MainClass

We should specify a main class in the JAR file Manifest.

For Example: If you have a Demo class.

public class Demo
{
    public static void main(String[] args)
    {
        System.out.println("Hello world. Happy Learning");
    }
}


manifest.mf will be:

Manifest-version: 1.0
Main-Class: Demo
Now, you can run the code.
javac Demo.java
jar cfm test.jar manifest.mf Demo.class
java -jar demo.jar
answered Jun 1, 2018 by parth295
• 4,590 points

Related Questions In Java

+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,360 points

edited Nov 6, 2018 by Omkar 4,529 views
0 votes
3 answers

How to check whether a file exists or not in Java?

Using nio we can check whether file ...READ MORE

answered Aug 14, 2018 in Java by Sushmita
• 6,820 points
92 views
0 votes
10 answers

How to import a jar file in Eclipse?

Go to your project right click and ...READ MORE

answered Dec 10, 2018 in Java by Hola77
19,268 views
0 votes
1 answer

How to move or copy a file in Java

You can follow the below java.nio operations: public static ...READ MORE

answered Nov 2, 2018 in Java by geek.erkami
• 2,320 points
17 views
0 votes
1 answer

Retrieving the path of a running jar file

Its quite simple. Try using the below ...READ MORE

answered May 25, 2018 in Java by geek.erkami
• 2,320 points
514 views
0 votes
1 answer

How to run the JAR files in windows?

Following are the steps to run the ...READ MORE

answered May 28, 2018 in Java by parth295
• 4,590 points
45 views
+1 vote
10 answers

Unable to execute jar- file: “no main manifest attribute”

You Can Simply follow this step Create ...READ MORE

answered Dec 10, 2018 in Java by Sukesh
9,814 views
0 votes
2 answers

Include all the jars in a directory within the Java classpath

Just use lib/*   not lib/*.jar   That's the ...READ MORE

answered Apr 6 in Java by anonymous
1,340 views
0 votes
3 answers

How to read a Text File in Java?

You can use readAllLines and the join method to ...READ MORE

answered Jul 27, 2018 in Java by samarth295
• 2,190 points
36 views
0 votes
2 answers

How to read a text file in Java?

You can use Scanner class to read ...READ MORE

answered Aug 9, 2018 in Java by parth295
• 4,590 points
35 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.