[Solved] Runnable JAR


I haven't seen any tutorial for creating a jar. Sorry if I've missed it.

I'm trying to export my project as a runnable jar (Eclipse, WinXP). Here's what I've done:

  • I've run build.xml. Many jme- and jmetest-jars were created in my jme/target folder.
  • I've right clicked my project and chosen Export -> Java -> Runnable JAR file. I chose the run configuration for the class containing the main method. The project exports to a jar-file, but with warnings (these are warnings in jme-source files).

    I try to run the file using the command java -jar test.jar and I get this

11.mai.2009 16:02:43 class the.pack.Test start()
SEVERE: Exception in game loop
java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at org.lwjgl.Sys$1.run(Sys.java:72)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.lwjgl.Sys.doLoadLibrary(Sys.java:65)
        at org.lwjgl.Sys.loadLibrary(Sys.java:81)
        at org.lwjgl.Sys.<clinit>(Sys.java:98)
        at org.lwjgl.opengl.Display.<clinit>(Display.java:129)
        at com.jme.system.lwjgl.LWJGLPropertiesDialog$ModesRetriever.run(LWJGLPr
        at com.jme.app.AbstractGame.getAttributes(AbstractGame.java:252)
        at com.jme.app.BaseGame.start(BaseGame.java:67)
        at the.pack.Test.main(Test.java:21)
11.mai.2009 16:02:43 com.jme.app.BaseSimpleGame cleanup
INFO: Cleaning up resources.
11.mai.2009 16:02:43 com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
11.mai.2009 16:02:43 com.jme.app.BaseGame start
INFO: Application ending.

What have I missed?

I have a second project too which uses jME Physics 2. How do I export this project to a runnable JAR?

Thanks in advance for any help!

Don't forget to set java.library.path to allow Java to find the third party libraries and the class path to allow Java to find the native libraries (.so under Linux, .jnilib under Mac, DLL under Windows).

nednull said:

What have I missed?

I have a second project too which uses jME Physics 2. How do I export this project to a runnable JAR?

Thanks in advance for any help!

If you want others to run your jar right out of the gate, you might want to look into using FatJar (Eclipse plugin):


it will package all project related files/jars into a single runnable jar.  I have used this before and it works great.  As a note, when putting together the FatJar you have to pay attention to the same gotchas as you do with WebStart -- mainly your resource locator calls might need to be adjusted and your assets/textures directories will need to be registered in Eclipse to make it into the final FatJar.

Thank you, your help is much appreciated!

I've made a working jar now with Fat Jar plugin - good things!

I have to start it with this line though:

java -Djava.library.path=D:workspacejmeliblwjglnativewindows -jar proj_fat.jar

I googled a bit and read that this path variable isn't writable. Is this correct? How do I avoid specifying this path every time?

Hey i'm currently on the same topic.

You are right, the classpath and librarypath declaration is ignored if you run you jar by

java.exe -jar myAppJar.jar

What you can do instead is to run it without the -jar command.

then you are able to specify the classpath and the librarypath and it works equally.

My batch looks like this:

java -Xmx300m -Djava.library.path=./lib/native;./lib -cp ./lib/AbsoluteLayout.jar;./lib/jgn.jar;./lib/jinput.jar;./lib/jme.jar;./lib/jmeutil.jar;./lib/jogg-0.0.7.jar;./lib/jorbis-0.0.15.jar;./lib/junit-4.1.jar;./lib/luajava-1.1.jar;./lib/luaJava-native.jar;./lib/lwjgl.jar;./lib/lwjgl_util_applet.jar;./lib/MD5Importer_jME1.0_v1.2.4_Java5.jar;./lib/mysql-connector-java-5.1.7-bin.jar;./lib/PDF-Renderer.jar;./lib/swing-layout-1.0.3.jar;./lib/Utils.jar;./lib/VB3DHUD.jar;./VB3DClient.jar com.pass.vb3d.quickwin.VB3DServer

It's structure is:

java.exe -Xmx -librarypath[..] -classpath[.. incl. the mainJar] Main.Class.with.package