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.
Good post. I definitely love this site. Keep it up!
ERROR:: Could not find or load main class org.ninjacave.jarsplice.JarSpliceLauncher
I get a “Duplicate Entry: com/apple/eawt/Application.class” exception
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?
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.
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???
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.
Sorry for the late reply. Do you still have this problem? If so, try running the program through command prompt to see if there are any error messages.
I use Netbeans, so is there a way to do this using that?
Yes, in Netbeans you can also create executable jar files. https://netbeans.org/kb/articles/javase-deploy.html#Exercise_1
Yes, you can export executable jars with Netbeans, too.
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.
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
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.
Also I noticed that you said to put them in an external folder. Minecraft doesn’t do that… So there must be a way.
Having this same problem. Found answer?
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(…)’.
Are there any advantages/disadvantages of having images etc. in the .jar file?
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.
Ok, I done it nevermind.
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?
Either store all the images in the jar-file, or place them in some kind of application folder (%APPDATA% on Windows, ~/Library/Application Support on Mac).
But how? What do I call the folder and reference it?
Never mind. To all that had my problem, you need to put in %appdata% on Windows, ~/Application Support/YourProgram.
Need more!
Haha. Working on it..