Thursday, January 7, 2010

Create an Executable File Using Java

If you are looking to make your Java application an executable file, you might want to use the Fat.jar plugin. You can download it from this website: http://sourceforge.net/projects/fjep

I downloaded the net.sf.fjep.fatjar_0.0.31.zip from their website.

Unzip the zip file using winzip or another tool.

Copy the net.sf.fjep.fatjar_0.0.31.jar from the zip folder and paste it in your eclipse/plugin directory.

Restart eclipse.

Select on the Java project that you want to make executable with the right mouse button and then select Build Fat Jar.

In the popup menu, select the class that contains the main and press finish.

It will tell you which directory it placed the newly created jar file.

Open a command prompt and traverse to the directory where your newly created jar file is located.

Type (myjar is the name of your jar file you created): java -jar myjar.jar.

If you get the UnsupportedClassVersionError, you might have compiled your code with a new version of Java. In eclipse, you can change the compliance level to make sure your code is compliant for older versions of Java. You can do this by selecting the window menu in eclipse, select preferences, Java and then select compiler.

0 comments: