Skip to main content

Java JAR Command

Creating a JAR

The following creates a jar file and sets the entry point in Manifest.txt:

jar cfe <compiled>.my-app.jar <package>.<package1.MainClass> <package1>/package1/*.class <package2>/package2/*.class

Reference: https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

Be sure you are in the correct classpath directory (above your package directory).  This is the same directory level where you can compile .java files and execute .class files:

javac package1/MyClass.java
java package1.MyClass <arg0> <arg1> .. <argN>

Executing a JAR

The following command executes a compiled JAR file:

java -jar <compiled>.my-app.jar <arg0> <arg1> .. <argN>