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,840 points
329 views

1 answer to this question.

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,600 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,380 points

edited Nov 6, 2018 by Omkar 6,156 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,840 points
129 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
32,346 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
20 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
752 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,600 points
60 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
15,456 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,762 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
61 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,600 points
41 views