1

I am finishing up a game that I developed using Java3D. Since Java3D does not come with the standard JRE, all of the people who I am giving this game to will have to download Java3D. Some of my friends are a little less computer savvy so I thought it would be a lot less work to just write the Jars to the disk and dynamically load them in Java. Is there a better solution to this? Or is dynamically loading the Jars the way to go?

I have installed Java3D on another computer of mine from here:

It was a pretty quick installation but it would be better if you didn't have to download anything at all. If they are only going to use Java3D for my game then it doesn't really seem logical for them to go through the trouble of downloading it.

Are there any more efficient solutions to this? Is dynamically loading the Jars just the way to go?


EDIT

Here is my problem simplified:

  1. Java3D is not a standard part of Java, it is an extension that must be installed separately
  2. Java3D consists of 3 Jar Files (j3core.jar, j3dutils, vecmath)
  3. I want to be able to run my game on other computers without them having to download the Jar files

Now here is my simplified question:

How do I run Java3D on a computer that doesn't have Java3D installed? I want to write the Jar files to a CD, along with the game, and be able to play the game right off the CD, no installations no downloads. How can I do this?

John
  • 3,769
  • 6
  • 30
  • 49

3 Answers3

1

If you are distributing it over disk, you can wrap your application in a setup executable (for instance using the free Inno Setup). Once the users put in your disk, the setup will start. You can configure your setup in Inno Setup to also install the correct version of Java3D.

I think that is how most of the disk-distributed games work. It takes a bit to get the hang of those more advanced setup wrappers, but they are worth it. I don't know anything else than Inno Setup, but it was able to handle any of my requirements so far that's why I recommend that one.

brimborium
  • 9,362
  • 9
  • 48
  • 76
  • If I wrapped it, then It would only be able to run on windows, I want it to be able to run on many different systems, which is why I am packing my program into a Jar file. – John Aug 08 '12 at 23:52
  • I am sure there are some platform independent setup wrappers? And I guess Java3D also has different installers for the various operating systems. So I don't think that you get around handling every operating system you want to support separately... Those setup wrappers just simplify this task hugely... – brimborium Aug 09 '12 at 09:00
1

The jars are not platform specific, the native code in the dynamic libraries is. The dynamic libraries are already loaded as they are called for in code. If you take a look back at that code you will see that loadLibrary() does not ask for the extension. There is a reason for this, JNI (the Java Native Interface) looks for certain extensions based on what system it is running on. For this reason just package all the dynamic libraries where JNI can find it, such as right next to your application and JNI will take care of the rest.

Some code to point you in the right direction:

Blah.java

public class blah{
    public native void meh();

    public static void main(String args[]) {
        meh();
    }
}
static {
    System.loadLibrary("thing");
}

Blah.cpp

#include <jni.h>
#include <iostream>
#include "Blah.h"

JNIEXPORT void JNICALL Java_Blah_meh() {
    cout << "Meh.";
}

Blah.cpp (with the Blah.h generated by the javah program) is compiled into a dynamic library for each major system (thing.dll, thing.dylib, thing.so). Blah.java is compiled into a .class file, toss it in a jar just for ease for execution. Now for the important part, the layout of files!

ThingApp //that's a folder
  |thing.dll
  |thing.dylib
  |thing.so
  |Blah.jar

Put this on any system and JNI will find the right file for the system due to the extensions, load the library into memory, execute the code, and print out "Meh.". JNI finds the files because they are in the PATH environment variable (or the system equivalent). The PATH includes the folder the executed code/program is in, folders set with the java.library.path system property, and the folders included int he PATH variable itself.

Basically you just need to worry about the part about the PATH as everything else is done for you!

yodal
  • 425
  • 1
  • 4
  • 10
  • Can you post some example code to push me in the right direction? – John Aug 09 '12 at 03:37
  • How do I get/generate the DLLs for Java3D? – John Aug 10 '12 at 00:08
  • @john Sorry for the wait. You can find the dynamic libraries in the various zip files here: http://java3d.java.net/binary-builds.html The dynamic libraries for Mac are not included as Apple makes their own distribution of Java and I believe they include Java3D with it. – yodal Aug 12 '12 at 02:35
  • i figured it out yesterday and i distributed it, thanks for your help it really sped up the process! – John Aug 12 '12 at 17:09
1

Download the classes from here: http://java3d.java.net/binary-builds.html and extract the included zip file. Extract the jar files (vecmath, j3dcore, j3dutils) in the lib folder to your class folder. Bundle your class folder to a single jar file.

Now follow these steps to add the libraries (*.dll, *.so) from the bin folder in the above zip file to your jar file: How to make a JAR file that includes DLL files?

Community
  • 1
  • 1
sina72
  • 4,931
  • 3
  • 35
  • 36