Creating executable Jar files in Java
When all is said and done, in your program in Java, usually you are left with several class files. Sending this file to a friend can be difficult, and thats when you use the .jar “Java ARchive”.
to create just a jar file. use:
jar cf myJar.jar *.java to make it executable jar cfe myJar.jar *.java *.class and to run it java -jar myJar.jar
the other method to create executable jar files is using the manifest.
java cfm myJar.jar MANIFEST.MF *.java *.class
The code stands for the following. “java” the compiler, “cfm” create – file – manifest, “myJar.jar” name of the jar file you will create, “MANIFEST.MF” this tells it will be a manifest file, “*.java” this will include any .java file in the current working directory, “*.class” will take any .class files in the current working directory.
Note that you do not need to include the .java files, only do this if you want to include your source code in your jar file.