我一直试图让GitLab CI在没有运气的情况下构建我的LWJGL项目,经过大约一个小时的修补我把它作为我的.gitlab-ci.yml:
image: java:8-jdk
buildtest:
script:
- mkdir bin
- javac -cp dependencies/lwjgl/lwjgl.jar -d bin/ src/*.java
- cd bin
- java HelloWorld
然而,在最终正确编译之后,当运行代码时,它会得到以下日志:
$ mkdir bin
$ javac -cp dependencies/lwjgl/lwjgl.jar -d bin/ src/*.java
$ cd bin
$ java HelloWorld
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/glfw/GLFWKeyCallback
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFWKeyCallback
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
ERROR: Build failed: exit code 1
在我看来它找不到org.lwjgl.glfw.GLFWKeyCallback
,但是在本地编译时它可以正常工作。所以我无法弄清问题是什么,有什么想法吗?
编辑:
在搞砸了这个之后,我最终在我的机器上尝试了这个,以下工作在命令提示符下,但不是在shell脚本中,并且因为GitLab CI使用linux它也不能在那里工作。 这是我编写的shell脚本,可以快速测试以及新错误:
mkdir bin
javac -cp dependencies/lwjgl/lwjgl.jar -d bin/ src/*.java
cd bin
java -cp ../dependencies/lwjgl/lwjgl.jar; -Dorg.lwjgl.librarypath=../dependencies/lwjgl/native/ HelloWorld
错误(我知道它对java.exe的用法,但它会打印出那个和最后的错误):
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
The default VM is server.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
Warning: this feature is deprecated and will be removed
in a future release.
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
Warning: this feature is deprecated and will be removed
in a future release.
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
bash: -Dorg.lwjgl.librarypath=../dependencies/lwjgl/native/: No such file or directory
我知道这个目录是存在的,因为我可以通过命令提示符以下列方式使它工作:
javac -cp dependencies/lwjgl/lwjgl.jar -d bin/ src/*.java
cd bin
java -cp ../dependencies/lwjgl/lwjgl.jar; -Dorg.lwjgl.librarypath=../dependencies/lwjgl/native/ HelloWorld
从命令提示符版本输出:
E:\test\bin>java -cp ../dependencies/lwjgl/lwjgl.jar; -Dorg.lwjgl.librarypath=../dependencies/lwjgl/native/ HelloWorld
Hello LWJGL 3.0.0b SNAPSHOT!
E:\test\bin>
答案 0 :(得分:1)
您必须将库路径设置为包含本机文件的文件夹。
java -Dorg.lwjgl.librarypath=path/to/natives HelloWorld
您可以在LWJGL zip文件的.so
文件夹中找到文件(结尾为.dylib
,.dll
和native
)。