After being JAR, what's next?

Started by illuminist, May 15, 2010, 16:03:07

Previous topic - Next topic

illuminist

I've build my game as JAR file run run it on MSwindows, it work.

But after I passed it to Ubuntu on VMware, it said java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path.

What should I do?

illuminist

If anyone has idea about integrated java environment in project for cross platforming, tell me please.

Matthias

You need to specify the property "java.library.path" to point to the native files for the correct OS like this:
java -Djava.library.path=natives/linux -jar myApp.jar

On windows it will look into the current folder by default - on Linux you have to explicitly tell it where to look

kappa

If you still want to manually distribute it your app, here is an example of how you can use batch files to do it. (its using a pretty old version of lwjgl so you'll have to update it)

alternatively you can use java web start.

Ciardhubh

You can set the library dir in Java, so you don't need a batch file.

Here's how I did it some time ago (run this before loading LWJGL, the idea is to get the directory of the .jar and work from there by adding subdirs based on OS):
       /* Set lwjgl library path so that LWJGL finds the natives depending on the OS. */
        String osName = System.getProperty("os.name");
        // Get .jar dir. new File(".") and property "user.dir" will not work if .jar is called from
        // a different directory, e.g. java -jar /someOtherDirectory/myApp.jar
        String nativeDir = "";
        try {
            nativeDir = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().
                    toURI()).getParent();
        } catch (URISyntaxException uriEx) {
            try {
                // Try to resort to current dir. May still fail later due to bad start dir.
                uriEx.printStackTrace();
                nativeDir = new File(".").getCanonicalPath();
            } catch (IOException ioEx) {
                // Completely failed
                ioEx.printStackTrace();
                JOptionPane.showMessageDialog(this, "Failed to locate native library directory. " +
                        "Error:\n" + ioEx.toString(), "Error", JOptionPane.ERROR_MESSAGE);
                System.exit(-1);
            }
        }
        // Append library subdir
        nativeDir += File.separator + "lib" + File.separator + "native" + File.separator;
        if (osName.startsWith("Windows")) {
            nativeDir += "windows";
        } else if (osName.startsWith("Linux") || osName.startsWith("FreeBSD")) {
            nativeDir += "linux";
        } else if (osName.startsWith("Mac OS X")) {
            nativeDir += "macosx";
        } else if (osName.startsWith("Solaris") || osName.startsWith("SunOS")) {
            nativeDir += "solaris";
        } else {
            JOptionPane.showMessageDialog(this, "Unsupported OS: " + osName + ". Exiting.",
                    "Error", JOptionPane.ERROR_MESSAGE);
            System.exit(-1);
        }
        System.setProperty("org.lwjgl.librarypath", nativeDir);