Skip to main content

3D application in runnable JAR?

3 replies [Last post]
deadfa11
Offline
Joined: 2010-06-28
Points: 0

Howdy.

I threw together a very basic 3D application from the early chapters of the Sun J3D tutorial, in which my main class extends Applet, and I have a separate viewer class that uses MainFrame to generate a window for the applet to live in. I would like to package this application into a runnable JAR file so I can show it to friends and so on who might not have the JDK available or the Java skills to compile and run manually.

What I tried to do is use Eclipse to Export... > Runnable JAR File, hoping that would produce a tidy package for my purposes. However, whenever I double click the JAR, I get a momentary busy cursor, then nothing.

After trying the jar on the command line and inspecting the resulting stack trace, I realized the requisite DLL files that come packaged with Java3D were not included in the JAR.

Is there a way to include said DLL files in the runnable JAR file?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
deadfa11
Offline
Joined: 2010-06-28
Points: 0

I managed to figure it out after several hours of trying various things.

For future askers of this question, here's what I did. I used the following code in my application to manually load the DLL files:

[code]
String path = System.getProperty("user.dir") + "\\lib\\";
System.load(path + "j3dcore-d3d.dll");
System.load(path + "j3dcore-ogl.dll");
System.load(path + "j3dcore-ogl-chk.dll");
[/code]

I then used Eclipse to produce a runnable JAR, same as before, and then I put the required DLL files in a folder named "lib" which is in the same directory as the JAR file.

Then I created a shortcut, and changed its "target" field to "java -jar -Djava.library.path=.\lib\ myJarFile.jar".

This way I can package the jar, lib folder, and shortcut together into an easily usable application for the technologically challenged. All they have to do is extract the files, and double click the shortcut.

Remember, this solution is Windows-specific. On systems without the dll files, or with different file separators, different code and methods will be required.

puybaret
Offline
Joined: 2004-12-04
Points: 0

Here's an other solution I used for Sweet Home 3D.
Zip all you class files, jars and dlls in an executable jar with a main class that will use a specific class loader to extract jars and dlls in temporary files first.

You may test this solution with [url=http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.5.jar]SweetHome3D-2.5.jar[/url] Jar executable which uses this [url=http://sweethome3d.cvs.sf.net/viewvc/sweethome3d/SweetHome3D/src/com/eteks/sweethome3d/SweetHome3DBootstrap.java?revision=1.23&view=markup]main class[/url] and this [url=http://sweethome3d.cvs.sf.net/viewvc/sweethome3d/SweetHome3D/src/com/eteks/sweethome3d/tools/ExtensionsClassLoader.java?revision=1.6&view=markup]class loader[/url].

sproketboy
Offline
Joined: 2006-08-07
Points: 0

Hey that's pretty cool thanks!