Hi everyone, I've been learning LWJGL and I have a program right now I'd like to send to my friends. It's dependencies are Slick_util.jar, lwjgl.jar, and lwjgl_util.jar. I am using Eclipse IDE to program, so my project has these 3 External Jar files loaded into its Build Path. I hit the Green Arrow to run my program, and it runs great.

Because I'm using Eclipse, I'm a bit spoiled when it comes to running my programs. I know how to do javac Class.java to build program in command line, but have no idea when it comes to executable jar files with 3 dependencies and a folder called Textures with some images in it.

Could you give me a hand, perhaps in walk-through format so others can benefit and use as a reference? Thanks!

I like to use ant to generate distributable jars - eclipse can do it, but the process is a bit laborious.I use the GenJar task. It examines class dependencies and only pulls in the classes that you are actually using. It can also fold in entire library jars so you're left with one self-contained jar. You'll still have to have to distribute the natives separately though.

Check out an example build.xml here. It compiles few other eclipse projects into a build directory and then points genjar at it. The "fatjar" task pulls in the lwjgl jars and produces a single executable jar, the "jar" task creates a webstart-ready jar that doesn't include libraries - they will be handled by webstart.

GenJar gotcha: It is a lying, duplicitous cur. If it encounters problems when resolving class dependencies, it complains that it can't find the entry point class where you told it to start the analysis. This causes enormously annoying but-it's-right-bloody-there! confusion. Run ant with the "-d" flag to see where it is actually having problems.

On a side note: I wouldn't mind at all if links to lmgtfy.com were automatically filtered out by the forum.The combination of a miniscule amount of actual help and a massive wedge of passive-aggresive you're-so-thick implication is entirely odious.

You should have checked the google results. It's not so easy, since you have to handle the native libraries, too, which usually involves writing some fancy wrapper to unpack them to disk temporarily and hand the location over to the java.library.path system property...

You should have checked the google results. It's not so easy, since you have to handle the native libraries, too, which usually involves writing some fancy wrapper to unpack them to disk temporarily and hand the location over to the java.library.path system property...

And since I'm feeling helpful, here's the code from Tectonicus that does exactly that:

Are you asking how to make an executable JAR using Eclipse, where the complication is the inclusion of the external libraries?These guys are great:http://www.eclipse.org/forums/The folks at the "Newcomers" area, especially Russell Bateman, have been tremendously helpful.

When I do an File->Export, I choose "Jar File" as a destination instead of "Runnable Jar File". The last page: "JAR manifest specification" lets you indicate the application entry point that will run when you click on the JAR file. Thus, you have an executable JAR. The option on "Runnable Jar File" frankly mystifies me. (Not difficult to do. ) One has to select a "launch configuration"?! I have not worked with such objects. And there seems to be no need since simple JAR exports have worked fine for me so far.

One gotcha I run into is that one should double-check the tree on "JAR File Specifications"(second page of export). Expand it completely and make sure all the packages needed are checked, including clicking on the constituent packages to make sure all the class files in them are also checked. (If your cursor is on a given class file when you click export, the default might be to only export that single class file.)

Sounds like you may already know about Properties->JAVA BUILD PATH->Libraries. When I do a WAR export, I have to make sure all the needed libraries are ALSO included in Properties->Deployment Assembly. Seems like needless duplication to me, to have to specify libraries in two places. But the folks at Eclipse have their reasons, I'm sure.

My apologies in advance if this answer is at too basic a level. (A risk when a nOOb attempts to answer a topic.)

"We all secretly believe we are right about everything and, by extension, we are all wrong." W. Storr, The Unpersuadables

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org