9

I'm making a basic game in Java using the LWJGL Library via Netbeans.

I've created a library with the lwjgl, lwjgl_util, and jinput .jar's, and I added -Djava.library.path=C:\LWJGL\native\windows to the "Run" category in the project's properties.

When I run the file in Netbeans, it runs perfectly with no issue. But when I run the .jar via double-clicking the file, nothing pops up (not even the momentary cmd error window, as far as I can tell). And when I run the file via command line, I get:

C:\Users\200160765>java -jar "C:\Users\200160765\Documents\NetBeansProjects\Game
\dist\Game.jar"
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.libr
ary.path
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at org.lwjgl.Sys$1.run(Sys.java:73)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
        at org.lwjgl.Sys.loadLibrary(Sys.java:82)
        at org.lwjgl.Sys.<clinit>(Sys.java:99)
        at org.lwjgl.opengl.Display.<clinit>(Display.java:130)
        at game.Draw.createWindow(Draw.java:198)
        at game.Draw.init(Draw.java:214)
        at game.Draw.run(Draw.java:56)
        at game.Main.main(Main.java:9)

I've tried moving the DLL's and .jar library files around to the 'lib' folder in the same directory as Game.jar, and moving them to the same directory as Game.jar, but I get the same error. Could someone help me as to why I can't seem to get this working outside of netbeans?

Stephen Wilkins
  • 125
  • 1
  • 1
  • 8

7 Answers7

9

you have to point the jvm to where the native files are located using a command line parameter -Djava.library.path="path/to/natives". You could use a batch (.bat) file to specify this and start your application for you.

Alternatively you can use a tool like JarSplice to create a single executable jar file from all your jars and at the same time include your native files inside it. It automates the tricky part of specifying the natives manually and provides a nicer end user experience.

To use JarSplice just select your game.jar, lwjgl.jar, lwjgl_util.jar, and jinput.jar in the jars tab. Then all the *.dll, *.so, *.dylib and *.jnilib files in the natives tab. Add your main class on the class tab and create the single executable jar.

Gavin
  • 842
  • 5
  • 5
  • 1
    I'm not that familiar with .bat file syntax, but I tried that route: '@echo off java -jar Game.jar -Djava.library.path=C:\LWJGL\native\windows' And I still got the same error. – Stephen Wilkins Jul 05 '11 at 21:29
  • In addition, the Fat Jar thing works, but the textures on the blocks I currently am rendering do not load...however, this may be a result of the packing into a .jar and not the packing into a Fat Jar. – Stephen Wilkins Jul 05 '11 at 21:57
  • yeh just make sure you're not loading any textures using a File or FileInputStream since those can't be used to load textures for inside a jar. – Gavin Jul 05 '11 at 22:11
  • So what exactly is the correct .bat file syntax? Or how would I go about obtaining the png for LWJGL without FileInputStream? – Stephen Wilkins Jul 05 '11 at 22:33
  • 2
    @Stephen Wilkins: You have to place the -D parameter before the -jar parameter, because otherwise it will be interpreted by the Java application and not by the JVM. – Robert Jul 05 '11 at 22:34
  • Ah; there we go. Thanks a bunch! – Stephen Wilkins Jul 05 '11 at 23:11
3

LWJGL needs the native components for your particular platform to be in java.library.path. These are in the subdirectory native in the LWJGL distribution and end in .so on Linux, OSX and Solaris and .dll for windows.

Ben Jackson
  • 90,079
  • 9
  • 98
  • 150
  • I know it needs the DLL's, but what I don't know is how Netbeans finds the DLL's fine, but the .jar does not, and how I tell the .jar that. – Stephen Wilkins Jul 05 '11 at 21:39
2

When I had this issue, it was because i accidentally put the argument to specify the location of the natives (-Djava.library.path=/native/) in the field called 'Arguments' under the run category of the options panel, instead of 'vm Options'. As seen here: http://s30.postimg.org/6f90akidt/Capture.png

0

I had this problem and fixed it using jarSplice (http://ninjacave.com/jarsplice)

make sure you delete all of the preplaced natives in your jar before you create the fat jar, otherwise it will create a duplicate error

0

I also got the same error and then realised that I named the file "my_lib.zip" instead of "my_lib.jar". Maybe it may help someone.

efeyc
  • 2,122
  • 2
  • 27
  • 39
0

Another thing to check:

  • If you are using a 32 bit JVM, you need 32 bit libraries. (Even on a 64 bit OS)
  • If you are using a 64 bit JVM, you need 64 bit libraries.
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

And yet another way to do this is with Java Web Start (jnlp): http://lwjgl.org/forum/index.php?topic=3763.0

This makes sharing your project easier in some ways.

Jim
  • 3,476
  • 4
  • 23
  • 33