Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Java program into jar?

Tags:

java

jar

A little help from you all... I was trying to convert a simple java program into jar but nothing seems to have happened. I have 2 files: Tester.java , Tester.Class. Then I used this command line:

jar -cvf Tester.jar Tester.class

The .jar file was created but nothing seems to work. What did I miss?

like image 495
firestruq Avatar asked May 22 '10 08:05

firestruq


1 Answers

To run the program in the jar file you created you would need to execute

java -cp Tester.jar your.package.Main

A more convenient way to execute the jar is to be able to do

java -jar Tester.jar

That, however, requires that you specify the main-class in a manifest file, that should be included in the jar-file:

  • Put

    Manifest-Version: 1.2
    Main-Class: your.package.Main
    

    in manifest.txt

  • And to create the jar:

    jar cvfm Tester.jar manifest.txt Tester.class
    
like image 183
aioobe Avatar answered Sep 19 '22 23:09

aioobe