4

Good day!

I created jar file (using Netbeans) and i can't start it. This project uses lwjgl libraries. Inside my IDE it works well.

I use next command:

java -jar LWJGL_TimerExample.jar 

Answer is:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
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 Sourse.TimerExample.start(TimerExample.java:32)
at lwjgl_timerexample.Main.main(Main.java:21)

Other projects (without this libraries) work fine. How can i solve this error?

My Manifest is:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.6.0_26-b03-384-10M3425 (Apple Inc.)
Main-Class: lwjgl_timerexample.Main
Class-Path: lib/jinput.jar lib/lwjgl.jar lib/lwjgl_util.jar
X-COMMENT: Main-Class will be added automatically by build
wattostudios
  • 8,666
  • 13
  • 43
  • 57
ExiRe
  • 4,727
  • 7
  • 47
  • 92

2 Answers2

4

It's not going to work the way you're trying to currently do it, since you need to have the native files along side the jar and point to them via the '-Djava.library.path' parameter.

If you just want a single jar and want to avoid the hassle of the command line and native files use the JarSplice tool. JarSplice is easy to use and will automatically handle the native file stuff for you.

1) Simply export your project (class and resources) to a jar (easier just to do it through your IDE).

2) Then run JarSplice, add all the jars you need to the jars tab (your app jar, lwjgl.jar, and any other external jar you're using).

3)Then on the natives tab add all the natives files (windows *.dll, linux *.so, mac *.dylib & *.jnilib).

4)On the class tab add your main class. Then create your jar.

You can then run this jar just by double clicking it (or if you wish via command line using 'java -jar yourapp.jar').

Gavin
  • 842
  • 5
  • 5
  • Sorry for stupid question... I have project with name LWJGL_TimerExample. It consists of 2 packages - Sourse and lwjgl_timerexample. Sourse contains TimerExample.java, lwjgl_timerexample contains Main.java. What is right way for main class? lwjgl_timerexample.Main? – ExiRe Jul 19 '11 at 16:22
  • yes, packagename.MainClass, so in your case it would be lwjgl_timerexample.Main if Main is the class you are trying to run. – Gavin Jul 19 '11 at 16:35
  • When I create fat jar, i received this error: Jar creation failed due to the following exception:duplicate entry: META-INF/MANIFEST.MF – Nafiz Bayındır Jul 31 '12 at 21:10
1

From the LWJGL wiki:

LWJGL consists of two parts, a java part and a native code part. You must setup both of these parts properly in order for lwjgl to work. In order to setup the java part you must add lwjgl.jar to the classpath (as an external library jar). As for the native part (*.dll files on windows, *.so on linux, *.jnilib on mac, etc) you must tell java which folder the natives are located in for LWJGL to be able to find them (use the -Djava.library.path=path/to/dir vm parameter to do this).

It seems that you're missing the second part - having the native library on your java.library.path.

Eli Acherkan
  • 6,401
  • 2
  • 27
  • 34
  • Yes my program use native part. I thought that IDE will add it automatically. – ExiRe Jul 19 '11 at 15:54
  • To the manifest? I'm not 100% sure about this, but looking at http://download.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Manifest I don't see a way to specify the library path in the manifest. Does it work when you add -Djava.library.path=/path/to/native/lib to the command line? – Eli Acherkan Jul 19 '11 at 16:03
  • A have tried that: java -jar -Djava.library.path=-Djava.library.path=/Users/serg/LWJGL_2_7_1/lwjgl-2.7.1/native/macosx LWJGL_TimerExample.jar Window appeared! – ExiRe Jul 19 '11 at 16:36