Sunday, February 1, 2015

Java: Create executable .jar file with command line

Continue my journey on compiling Java program in command line, I wonder how to create a runnable .jar without an IDE. Turns out it is fairly simple as I'm not dealing with a complex project.

To create an executable .jar:
jar -cvfe <output_name> <entry point> <class file>
e.g. jar -cvfe output.jar HelloWorld *.class

-c  create new archive
-v  generate verbose output on standard output
-f  specify archive file name
-e  specify application entry point for stand-alone application bundled into an executable jar file

How to create and execute JAR file in Java – Command line Eclipse Netbeans

No comments: