I'm making a game in Java using Slick2d, which depends on LWJGL. I can get everything to work in my development environment, but when I export it to a .jar, it needs the natives placed in the same directory as the .jar. What I'm asking is if it's possible to package the natives for all operating systems in the .jar, and automatically use the right ones depending on what OS was detected.

So, is this possible?

  • \$\begingroup\$ Hey Carter H. Since this question is not strictly related to gamedev but to packaging native libs into Java JARs in general this question would belong better at www.stackoverflow.com where you will probably receive a good answer faster. I've flagged your question to be moved there. \$\endgroup\$
    – Roy T.
    Mar 17, 2012 at 22:32
  • 1
    \$\begingroup\$ @Roy... as Slick2D and LWJGL are both rather game oriented, I can't help but think that this is indeed more game oriented than not. \$\endgroup\$ Mar 18, 2012 at 2:19

1 Answer 1


I recently had the same sort of issues.

I recommend the following:

First, get jarsplice.

Also, assuming that your dev environment is Eclipse, but if not, you'll need to do the equivalent.

  1. Export your game to a jar (NOT a runnable jar, just a regular jar)
  2. Start jarsplice. Add your jar.
  3. Add slick.jar, lwjgl.jar, and whatever other jars you are using from slick2d (for example, I use audio, and so usually need the jogg and jorbis jar file)
  4. Add the native-(OS).jar(like native-win32.jar, native-mac.jar, native-linux.jar) files in the slick lib directory. (DO NOT ADD THE NATIVES, THEY ARE IN THE JARS ABOVE)
  5. Set the appropriate main class.
  6. Create the fat jar
  7. Behold as your jar will work on windows, mac, and linux.
  • \$\begingroup\$ When exporting the project from Eclipse, I have to have the libraries included in the project or else I get compile errors. \$\endgroup\$
    – Carter H
    Mar 18, 2012 at 9:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .