Saturday, June 23, 2012

LWJGL Executable Jar Generation

Steps to generate an executable jar with Eclipse using LWJGL:

  1. File -> Export -> Java -> Runnable JAR file -> Next
  2. Define Export settings and Finish
  1. Download Jarsplice to add the native files to the executable jar.
  2. Start Jarsplice and set the floowing parameters:
  • ADD JARS - add your jar file
  • ADD NATIVES - add the natives in your LWJGL folder (windows and mac)
  • MAIN CLASSS - define the main class
  1. Press  Create Fat Jar to genere the executable jar file.

Common troubles:

  • Staring the jar does not work. Files load by your program may not be found. The following way to load resources works best for me:
URI uri = new URI("file://"+MYCLASS.class.getProtectionDomain().getCodeSource().getLocation().getPath());
File f = new File(uri).getParent(); //f is the absolute folder your jar resides in
  • Double clicking the jar does not work. (Typically, double clicking the Jar starts it with javaw, therefore there is no console output, which is hard to debug.)  Try starting your Jar in the command line with:
java -jar -myjar.jar
  • Generally it was some trouble to get this working correctly, specially for distributing your Jar you may not want to have users open their command line. I created a *.bat file to start the program with  java -jar -myjar.jar. (However this requires the PATH enviroment to be set, which is not done by a simple Java installation.) -> I will update this post if I find a good solution. (For example: Minecraft distributes its own exe which starts the minecraft.jar)

Saturday, May 26, 2012

Today's drawing

Today's creation, just an image. :)


Created in GIMP while using a tablet. It took me a few hours, since I am not a professional graphic designer.