Java path error - Library

I am trying to run my java game, but I have some problems with the java command line:

Here is what I type:

C:\>java -Djava.library.path=%cd%\lib -jar game.jar

And here is what I got:

 Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException at com.game.Main.main(Main.java:7) Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more 

I can start the game with Eclipse (with launch as a Java application), but after this menu I got the following error:

 Exception in thread "Thread-5" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.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:72) at java.security.AccessController.doPrivileged(Native Method) at org.lwjgl.Sys.doLoadLibrary(Sys.java:65) at org.lwjgl.Sys.loadLibrary(Sys.java:81) at org.lwjgl.Sys.<clinit>(Sys.java:98) at org.lwjgl.opengl.Display.<clinit>(Display.java:129) at com.game.displaygui.run(Unknown Source) at java.lang.Thread.run(Unknown Source) 

lwjgl.jar placed in the \lib folder.

Could you explain to me, I got it?

Thanks.

+4
source share
4 answers

This is because the lwjgl library consists of two components:

  • a .jar file that contains Java code
  • and a built-in binary library (which could be .so or .dll or .dylib according to your OS)

The first error you get is that you set the path to the library, which should contain the built-in library, but it contains .jar. This way you get java.lang.NoClassDefFoundError because you have to set either the library path to the folder that contains the built-in library or the class path containing the real lwjgl.jar file.

The second error you get with Eclipse is the sequential step: your class path contains the jar library, but it cannot find the built-in library attached to it, you can fix it as follows:

enter image description here

+9
source

You must specify explicitly which lib files to include (seperated by;):

 -cp %cd%\lib\lwjdl.jar;%cd%\lib\<another-lib>.jar 

Don't be tempted to use the * wildcard, as this does more harm than good (from previous experience :))

0
source

You use the java.library.path parameter to indicate the location of the loaded libraries. At the location indicated by this option, you will place all the dll or .so files needed by LWJGL. On the other hand, you need to make sure that all the necessary JAR files are in your classpath with the -classpath parameter. You currently have JAR files in the wrong directory.

0
source

In Eclipse, if you are using maven.

Add the following to the Run project: VM Settings.

 -Djava.library.path=yourpath/youproject/java/target/natives 
0
source

Source: https://habr.com/ru/post/1216423/


All Articles