LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: illuminist on May 15, 2010, 16:03:07

Title: After being JAR, what's next?
Post by: illuminist on May 15, 2010, 16:03:07
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?
Title: Re: After being JAR, what's next?
Post by: illuminist on May 15, 2010, 16:04:56
If anyone has idea about integrated java environment in project for cross platforming, tell me please.
Title: Re: After being JAR, what's next?
Post by: Matthias on May 15, 2010, 16:10:21
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
Title: Re: After being JAR, what's next?
Post by: kappa on May 15, 2010, 16:12:03
If you still want to manually distribute it your app, here is an example (http://kappa.dreamhosters.com/test/speedblazer.zip) 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.
Title: Re: After being JAR, what's next?
Post by: Ciardhubh on May 15, 2010, 16:43:36
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);