Eclipse --> Jar file?

Ok, yes, I know there’s jnlp, and I know how great Java Web Start is for games and such, I read all about that searching for related topics. But since I don’t have a server set up, and I’d rather just double-click a simple offline file, I want to figure out how to do .jar files for now. Also there’s something I like about making java applications as close as possible to the c++ .exe files, without actually having to be them.

That said, right now I’m trying to figure out how to make an executable jar file that contains the libraries for Xith3D. Specifically, I want it to contain the Xith3d.jar and vecmath.jar, such that any person who runs the file and does not have xith will be fine. Note that in this particular case, I already have JOGL installed on this computer, so I’m not attempting to include those files. I figure I can just reapply the same concept if I need to though.

To be absolutely clear, here’s a mini-screenshot of what my current package explorer looks like:

http://img197.imageshack.us/img197/7370/xithpath5tx.jpg

As you can see, I created a couple of Classpath Variables (probably a mistake for my objective…) and added them through the Project - Properties - Java Build Path - Libraries tab.

If I select my .java file then, and use “Run as application”, it works just fine. I get my standard frame, along with the basic colored cube in the view. When I take this file and use the standard File - Export - JAR File wizard, however, I get an “executable” file that returns the message “Could not find the main class. Program will exit.” in a dialog box at runtime.

So, evidently, I’m not actually putting anything in the jar, and what I’ve done is only helping Eclipse out (in terms of my situation, anyway). I’ve tried throwing around a few other file imports and such, but I really just don’t know what to do. Hopefully this is a easily solveable problem for the eclipse experts out there.

Appreciate your time.
Thanks.

.jar files don’t really work with native libraries. You don’t want to have to make your users install native libraries into their JRE.

The easiest is probably doing something like Xith3D’s .bat files. The easiest good way is for sure Java Web Start. A harder way is you can use something like Molebox which I believe lets you pack up your entire application into a single .EXE.

Will.

you can look for the fatjar plugin with makes a single (Ihuge ) jar of all your dependencies… It is slow but it works.

Oddly enough I use Eclipse all the time but have never been able to make an executable jar the way I want to. So I use netbeans for the jar creation…wierd but it works for me

Thanks hawk, I think that was what I was looking for. Hopefully (I haven’t tested it yet) it only includes a couple of extra libraries, i.e. the Xith and JOGL ones, and not the entire JRE. I will consider working with Java Web Start though.

Quick edit: Just tested and yes it works. :slight_smile: The files do appear to be a little larger than I would have expected (the whole jar is bigger than all the libaries inside of it?) but I might be able to cut it down somehow. Still it’s exactly what I wanted, and very very easy to use (about 20 seconds to set up the jar the first time, 3 seconds or so the second time, and maybe 5 seconds while it compiles the information).

You can cut out stuff like the test package and the demo directory. Perhaps actually the default distribution should include the demo’s as a seperate .jar file.

You can also dump debugging information (not recommenended unless your code is perfect).

I had a lovely list of which packages one can drop if they are not used, but with the new forums, my old URL is dead :’(

With the push to move all non-essential stuff to the Toolkit, and the property of the Toolkit where interdependancies are rare - cutting out unneeded stuff will be much easier in the future.

I personally use ant to do all my building and releasing. I find it very versatile, and it means I am not tied to a particular IDE nor do I have to load it up. Even stuff like creating a mac .DMG image or launching a the IzPack java installer is possible though ant relitivly easily.

Will.

Thanks for the file dumping advice, didn’t know it was holding so much extra stuff.

But the big issue with the fat jar is it seems to like to create two copies of everything. That is, within my “JOGL Test_fat.jar” I have two separate jars, “jogl.jar” and “main.jar” (this test isn’t using Xith, it’s just JOGL). But if you extract “main.jar”, you see “jogl.jar” included again, along with duplicates of a few other files it put in there. So while the jogl.jar is only 1 mb in size, my executable jar is 2 mb in size.

If I can’t resolve this I might have to just use webstart. I’ll see what I can figure out though.

eclipse has a feature ’ load dependencies ’ when exporting to a .jar archive … and i think that loads just the classes that the programm needs … or am mistaken there?

If there is I can’t find it…

Sorry for double posting but…

I got it working :slight_smile:

Although somewhat annoying to do, I successfully went into the over-sized jar file, opened the “main.jar”, deleted the extra jogl.jar file, and left a much-smaller main file there instead. Ran it on my other, non-jogl enabled computer, and it executed just fine.

This seems to be something of a bug in Fat Jar though.

According to the plugin’s name, it don’t seems to be any… :wink: ;D ;D

Update!

Good news, the creator of Fat Jar just recently updated the plugin, and fixed the bug with the duplicate files.

Although for some odd reason I seem to have trouble getting the jogl.jar file included singularly, I found that if I export an ANT build and then run that, I get exactly the jar I want.

Btw if anyone cares, jogl.jar + windows dll files + noob program results in a “fat jar” of about 1153 kb or so, less than 20 kb more than the jogl.jar file alone (remember there’s about 480kb of extra stuff). Not too bad.

http://fjep.sourceforge.net/ link to Fat Jar :slight_smile: