LWJGL Exporting as JAR

By the end of this tutorial you will have learned about distributing your LWJGL program as a jar-file using JarSplice.

Creating the jar-file containing only the source files

Right click your project in Eclipse and select Export. Select Runnable JAR File and click next. Enter your preferred export location and tick “Copy required libraries … generated JAR”.

Using JarSplice to create a comprehensive jar-file (LWJGL exporting)

Download the JarSplice application here. Open this jar-file by double-clicking on it. Click “Add JARs” and add the previously exported jar-file and the exported jar-file and the library jar-files. Go to “Add Natives” and select all the LWJGL native files. Go to “Main Class” and enter the class – with package definition – containing a main method that you want to execute. Go to “Fat JAR” and select the preferred export location and name.

Testing if it works

Double-clicking on this jar-file should open up your application. If it does not, open the Command Prompt on Windows or the Terminal on Macintosh, and write “java -jar ” followed by the path to the jar-file.

Conclusion

That concludes this tutorial. Should you have any questions or remarks, I would love to see them in the comments section below.

26 thoughts on “LWJGL Exporting as JAR

    1. Oskar Veerhoek Post author

      That’s unusual, I’ve never about that particular error before. It must have something to do with a double-definition of a part of Apple’s Java libraries. Have you tried reinstalling the workspace?

      Reply
    2. Aires Noronha

      That happens when you export your JAR file extracting required libraries into generated JAR (first option). It works copying everything it need into your jar and when jar splice joins then they get repeated. Try to export using the third option: copy required libraries into a sub-folder net to the generated JAR. It should work perfectly.

      Reply
    3. jay

      Whenever I export the project like you said, the textures don’t appear. They just give an error saying it cant find the images. How do you even do this???

      Reply
  1. Nolan

    I’m having trouble involving the fat jar when I create it. It doesn’t run and I tried just naming it the class and it cause my java SE Binary to crash. I’m not really sure what is going on, on Windows 7 btw. I feel like I have either too many natives or too little unsure really.

    Reply
  2. Natalie

    I was going to tell her that, but she hung up on me before I got a chance.
    Ink expenses are the most costly part of owning an inkjet printer.
    Look for similar devices in the future, particularly as
    the inkless paper technology is improved upon & made less costly to manufacture.

    Reply
  3. shane

    i try to use jarslice but everytime i specify my main class and try to run, it says cannot find or load main class…
    the main class is called Main, its in a package named examples. i then put in the main class as: examples.Main
    doesnt work.. i also tried: ForestFire.examples.Main, examples.Main.class, examples.Main.java…
    nothing is working… please help

    Reply
  4. SCOPE

    I tried doing that for one of my programs but then it couldn’t find the resources. If you load files like this “res/file.ext” then in the jar it will look like “file.ext”. When you run it, it looks for a file that isn’t there. How would I fix that? It crashes saying that it couldn’t find the resources.

    Reply
    1. SCOPE

      Also I noticed that you said to put them in an external folder. Minecraft doesn’t do that… So there must be a way.

      Reply
        1. Oskar Veerhoek Post author

          You can also store the resource files inside the jar-file itself (I believe this is what MineCraft does). To load a resource file in the same directory as a .class file, do ‘CustomClass.getClass().getResourceAsStream(…)’.

          Reply
  5. Chris

    I have a proble with extracting my LWJGL project into jar file. I’m doing every step that is written here, and there are no errors, bu at the end fat jar is not working. I’m using Windows7, maybe that is the problem.

    Reply
  6. Dollar

    Will this work for a large project, especially one that works with images? Will I be able to send the .jar to anyone, like my grandmother, and it will run perfectly for them after clicking on the file?

    Reply
        1. Anonymous

          Never mind. To all that had my problem, you need to put in %appdata% on Windows, ~/Application Support/YourProgram.

          Reply

Leave a Reply to David Cancel reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>