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,910 points
7,126 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 Parth
• 4,630 points

Related Questions In Java

0 votes
1 answer

How to run a .java file from command line passing arguments in Maven?

Hello @kartik, You could run: mvn exec:exec -Dexec.args="arg1". This will ...READ MORE

answered Jun 3, 2020 in Java by Niroj
• 82,880 points
19,782 views
+5 votes
4 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,450 points

edited Nov 7, 2018 by Omkar 79,301 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,910 points
3,529 views
+4 votes
11 answers

How to import a jar file in Eclipse?

Click on File > Import. The Import ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,120 points
351,444 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,680 points
10,319 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 Parth
• 4,630 points
888 views
+2 votes
13 answers

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

add a jar/manifest/attributes setting like this: apply plugin: ...READ MORE

answered Nov 27, 2018 in Java by krishti
213,799 views
0 votes
1 answer

Can't execute jar- file: “no main manifest attribute”

First, it's kind of weird, to see ...READ MORE

answered Dec 23, 2020 in Java by Gitika
• 65,910 points
2,116 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 28, 2018 in Java by samarth295
• 2,220 points
2,097 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 Parth
• 4,630 points
754 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP