Java: create executable jar file with eclipse

The version of eclipse is:

Eclipse Java EE IDE for Web Developers.

Version: Indigo Service Release 1
Build id: 20110916-0149

At first, I use “export” to make a match.jar file, and ran it on Dos with:

java -jar match.jar

It shows the error:

Exception in thread “main” java.lang.NullPointerException
at sun.launcher.LauncherHelper.getMainClassFromJar(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

It’s said that it needs manifest file to define an entry for main class.

The manifest.mf should look like this:

Manifest-Version: 1.0
Main-Class: byjson.Match

But soon, I found that I should choose to make a “exacutable jar” on eclipse, don’t need to make manifest file manually. The process is as below:

1) Right click the project name on the project explorer; then choose “Export” on the popup menu.

2) then click “Java” folder in the popup window, choose “runnable JAR file”

Here I choose “Package required libraries into generated JAR”, probably other choices are also ok.

Leave the space for “Save as ANT script” empty.

Click “Finish”.

Under DOS, run the match.jar with the command:

java -jar match.jar

It works fine.

Leave a Reply

Your email address will not be published. Required fields are marked *