JAR stands for Java ARchive and is platform independent. By making all the classes into one JAR file, we make it portable that can be run anywhere and on any operating system or platform.
To execute a JAR file, one must have Java installed in their computer. Also the version of the Java should be up-to-date, so before proceeding further make sure your computer meets the requirement.
Second step is to make the JAR file executable. All class files of the application are collected at one place. A programmer must set an entry point to the main class containing the main method using the Manifest file "manifest.mf". To set an entry point use "-e" jar.
If you do not create a main class, your JAR files won't run. To create a main class use Main Class: [Package Name].[Class Name]. Put this file into JAR file in a subfolder named Meta-inf.
.jar files are executed from this entry point by compilers or JVM (Java Virtual Machine). The executable JAR files are different from other files as they have a hexadecimal field code on the first file. One can also set the entry point using .jar tool.
.jar file is executed from javaw.exe.
Now that you have made the JAR file executable, you can attach it along with any libraries the program uses.
To Run your .jar file type java -jar [Jar file Name] in the command prompt. To execute it on double click paste the path of executable file C:\Program Files\Java\j2rex.y.z\bin\javaw.exe" -jar "%1" %*
Point to remember:
A user does not normally create a jar files but they execute it quite often. IDE like Netbeans or Eclipse can also be used to execute a .jar file.
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial
Discuss: Java Execute Jar file
Post your Comment