Java - Library path error

后端 未结 4 829
野趣味
野趣味 2021-01-06 05:39

I\'m trying to start my java game but I have some troubles with the java command line:

Here is what I type:

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

相关标签:
4条回答
  • 2021-01-06 06:15

    You use the java.library.path option to specify the location of native libraries to load. In the location pointed to by that option you would place all dll or .so files required by LWJGL. On the other hand, you need to make sure that all required JAR files are on your classpath, via the -classpath option. Currently, you have your JAR files in the wrong directory.

    0 讨论(0)
  • 2021-01-06 06:17

    In Eclipse, if you using maven.

    Add the following to the project "Run" : "VM options" .

    -Djava.library.path=yourpath/youproject/java/target/natives
    
    0 讨论(0)
  • 2021-01-06 06:41

    This because lwjgl library is made by two components:

    • the .jar file which contains Java code
    • and the native binary library (which can be .so or .dll or .dylib according to your OS)

    The first error you are getting is because you are setting the library path, that should contain the native library, but it does contain the .jar. So you get a java.lang.NoClassDefFoundError because you should set either the library path to the folder that contains native library, either the classpath to contain the real lwjgl.jar file.

    The second error that you get with Eclipse is a successive step: your classpath contains the jar library but it is not able to find the native library attached to it, you can fix it in the following way:

    enter image description here

    0 讨论(0)
  • 2021-01-06 06:41

    You should 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 it will cause more harm than good (from previous experience :))

    0 讨论(0)
提交回复
热议问题