Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It is posible to create a core java program(helloworld!) as to get jar file or exe file?
Posted

A jar file is nothing more than a zip file that contains your compiled .class files and the resources needed by your application (html files, pictures, ...). A jar file might also contain a manifest file that stores some properties for your jar file, one of these properties is the "Main-Class" property that tells java which class should be executed when someone launches your jar file (with "java -jar <jarfile>" or by double-clicking/enter-pressing it if the .jar extension is associated with the "java -jar" command on your system).

In a large program every class can contain a main function (I often used this to write simple tests for each class), this is why you need to select one class file in the manifest as your main class.

A simply "Hello World" jar tutorial.
http://www.herongyang.com/Java-Tools/jar-Create-First-JAR-File.html[^]
The only problem with this tutorial is that it didn't set the "Main-Class" attribute in the manifest file. Create your manifest.mf file and write the "Main-Class: Hello" line into it and then redo the tutorial by specifying the "-m manfiest.mf" parameter too when you create your jar file. If your main class is inside a package (not in the default package) then specify the package as well: "Main-Class: package1.package2.Hello"

Run your jar: "java -jar hello.jar"
 
Share this answer
 
the keyword is "deployment" - if you want to create an application from your stuff you need to "deploy" it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900