Java – How to create a jar file from multiple packages

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 2.00 out of 5)

How to create a runnable jar file from multiple java packages.
The below example has two packages mypkg1 & mypkg2 with the below directory structure

As you can see below I have 3 java files and two packages

Example java main method file.

Create a Manifest file
Note: mypkg1 contains the main and One is the class called

Note: Make sure to leave two empty lines at the end

Lets first compile to java byte-code.

Now we are ready to compile / create the jar file.

To use the jar file just run

One last word about extra library files or any other static data.
By default java will search library and shared objects (so) files under the project folder/lib, make sure to include that in the jar file if needed.

alternatively use Apache Ant to auto build your project

Leave a Reply

Notify of