LWJGL builds with GitLab CI - java

I have been trying to get GitLab CI to build my LWJGL project with no luck, after about an hour of tinkering I have this as my .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
However after finally getting it to compile correctly, when it comes time to run the code it gets the following log:
$ 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
It seems to me that it cannot find org.lwjgl.glfw.GLFWKeyCallback, however when compiled locally it works fine. So I cannot figure out what the issue is, any ideas?
EDIT:
After messing around with this some more, I ended up trying this on my machine and the following works in command prompt, but not in a shell script and because GitLab CI uses linux it does not work there either.
Here is the shell script I wrote real quick to test along with the new error:
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
Error (I know its the usage for java.exe, but it prints both that and the error at the end):
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
I know for a fact that this directory exists though because I can get it to work in the following way with command prompt:
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
Output from command prompt version:
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>

You have to set the library path to the folder containing the native files.
java -Dorg.lwjgl.librarypath=path/to/natives HelloWorld
You can find the files (which have endings .so, .dylib and .dll) in the native folder of the LWJGL zip file.

Related

Passing JAR files as CMD arguments that are required as dependencies

I have a program running in Intellij Idea. It has the following dependencies added as a jar file
I want to run it using the command line and want it to detect the jar files automatically as dependencies. Is there any way to achieve that without using Gradle or Maven? Or I could pass the dependencies as command-line arguments?
I have tried this command but it throws an error:
javac -classpath lib/*.jar -sourcepath src/*
Error:
error: invalid flag: lib/okhttp-3.4.1.jar
Using java -cp says this:
java -cp lib/* -sourcepath src/*
error
Error: Could not find or load main class lib.okhttp-3.4.1.jar
Caused by: java.lang.ClassNotFoundException: lib.okhttp-3.4.1.jar
Used the suggested command and it says:
java -cp lib/gson-2.10.jar:lib/okhttp-3.4.1.jar:lib/okio-3.2.0.jar:lib/slf4j-api-2.0.6.jar src/Main.java

Sopaui git jenkins integration

Hi I am using below code in build step in jenkin
#!/bin/bash
pwd
cd ./eclipse-workspace/SoapUiTest
pwd
javac -classpath "lib/* -d ./bin ./src/defaultPackage/*.java"
java -cp "bin;lib/* org.testng.TestNG testng.xml"
while running job i am getting below error
javac: no source files
Usage: javac
use -help for a list of possible options
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
-zero to select the "zero" VM
-dcevm to select the "dcevm" VM
The default VM is server,
because you are running on a server-class machine.
-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.
An obvious error is the mixure of flags in flag values in javac command:
#!/bin/bash
pwd
cd ./eclipse-workspace/SoapUiTest
pwd
javac -classpath "lib/*" -d "./bin" "./src/defaultPackage/*.java"
java -cp "bin;lib/* org.testng.TestNG testng.xml"
javac command explanation: you specify where to find additional class binaries that the compilation depends on, where to output the compiled files and finally where to read the sources from.

Why cannot run compiled JavaFX 11 class?

Following instructions at https://openjfx.io/openjfx-docs/#install-javafx, I compiled the sample HelloFX.java via:
javac --module-path $PATH_TO_FX --add-modules=javafx.controls /Users/me/Documents/java/HelloFX.java
But now if I attempt to run that...
java --module-path $PATH_TO_FX --add-modules=javafx.controls /Users/me/Documents/java/HelloFX
... I get error:
Error: Could not find or load main class .Users.me.Documents.java.HelloFX
Caused by: java.lang.ClassNotFoundException: /Users/me/Documents/java/HelloFX
Yet the file reported as not found is there:
ls -l /Users/me/Documents/java/HelloFX.class
-rwxr--r-- 1 me staff 1336 Oct 30 16:01 /Users/murray/Documents/java/HelloFX.class
(I had already changed permissions to add u+x in case that was the issue, but apparently that was not the trouble.
What's wrong?
(Yes, $PATH_TO_FX does point to javafx-sdk-11/lib.)
This question was already answered in the openjfx-dev mailing list:
The "java" command expects a fully-qualified class name, not a file path as
its argument
For completion:
The javac command deals with filenames, which means you can compile a java file from any location:
javac [ options ] [ sourcefiles ]
However the java command deals with classes:
java [options] mainclass [args...]
where mainclass specifies the name of the class to be launched, not the filename or location.
Providing you have Java 11 installed (and JAVA_HOME is set at it), the JavaFX 11 SDK downloaded, and just following the getting started guide:
Download the HelloFX class to any location, i.e /Users/<user>/Downloads.
Open a terminal and cd to that location:
cd /Users/<user>/Downloads
Set the JavaFX path:
export PATH_TO_FX=/path/to/javafx-sdk-11/lib
Compile the class:
javac --module-path $PATH_TO_FX --add-modules=javafx.controls HelloFX.java
Check that HelloFX.class is created at the same folder level.
Run the class:
java --module-path $PATH_TO_FX --add-modules=javafx.controls HelloFX
It should run just fine.
Now, if you try to run the above command from a different location it won't work, because the HelloFX class is not available in the classpath.
So if you want to run this class from a different location you'll need to specify this classpath:
javac --module-path $PATH_TO_FX --add-modules=javafx.controls \
/Users/<user>/Downloads/HelloFX.java
java --module-path $PATH_TO_FX --add-modules=javafx.controls \
--class-path /Users/<user>/Downloads HelloFX

apache ant Could not find or load main class org.apache.tools.ant.launch.Launcher

I'm trying to compile a tool which uses apache ant on linux
https://github.com/lindenb/jvarkit
When I tried to compile the tool , I get n error.
$ make vcffilterjs
this is what I get when I'm running the command
echo "Compiling htsjdk with ${JAVA_HOME} = /usr/lib/jvm/java/jre/"
Compiling htsjdk with /usr/lib/jvm/java/jre/ = /usr/lib/jvm/java/jre/
echo "Compiling htsjdk library for java. Requires apache ANT. If it fails here, it's a not a problem with jvarkit."
Compiling htsjdk library for java. Requires apache ANT. If it fails here, it's a not a problem with jvarkit.
echo "And ${JAVA_HOME}/bin/javac should be >=1.7"
And /usr/lib/jvm/java/jre//bin/javac should be >=1.7
(cd /home/jannahS/jvarkit/htsjdk-1.139 && ant )
Error: Could not find or load main class org.apache.tools.ant.launch.Launcher
make: *** [/home/jannahS/jvarkit/htsjdk-1.139/dist/htsjdk-1.139.jar] Error 1
I have installed apache ant and tried to set ANT_HOME following google instruction
export ANT_HOME=apache-ant-1.9.6
ANT_OPTS="-Xms256M -Xmx512M"
PATH=$PATH:$HOME/bin:$ANT_HOME/bin
export ANT_HOME ANT_OPTS PAT
I also have set JAVA_HOME
export JAVA_HOME=/usr/lib/jvm/jre-1.7.0
export PATH=$JAVA_HOME/jre/bin:$PATH
When I run
ant --execdebug
exec "/usr/lib/jvm/java/jre//bin/java" -Xmx256M -classpath "apache-ant- 1.9.6/lib/ant-launcher.jar" -Dant.home="apache-ant-1.9.6" -Dant.library.dir="apache-ant-1.9.6/lib" org.apache.tools.ant.launch.Launcher -cp ""
Buildfile: build.xml does not exist!
Build failed
I don't know what else to do to make things to work. I can't compile the tool that I want to use without apache ant
Use full path in ANT_HOME, eg:
export ANT_HOME=/usr/lib/apache-ant-1.9.6
It dependes where it is exactly located
Could not find or load main class org.apache.tools.ant.launch.Launcher
In mac this is due to some environment issue if you install the ant using brew command,
copy the lib folder from the ant and paste it into the bin folder
now run the command issue is resolved:-)
issue reason
ant is trying to get the bin/lib/ant-launcher.jar file from the invalid path
In Mac, after running brew install ant, I had to run brew link ant to fully link ant to system environment.
Running brew link --verbose --overwrite ant I get:
Linking /usr/local/Cellar/ant/1.10.5...
ln -s ../Cellar/ant/1.10.5/bin/ant ant
ln -s ../Cellar/ant/1.10.5/bin/antRun antRun
ln -s ../Cellar/ant/1.10.5/bin/antRun.pl antRun.pl
ln -s ../Cellar/ant/1.10.5/bin/complete-ant-cmd.pl complete-ant-cmd.pl
ln -s ../Cellar/ant/1.10.5/bin/runant.pl runant.pl
ln -s ../Cellar/ant/1.10.5/bin/runant.py runant.py
6 symlinks created
And when running "ant" with no params from command-line:
Buildfile: build.xml does not exist!
Build failed
Which is what I expect if testing outside the context of an existing ant project.
Run "which ant" >> to know if the ant_home set. If not please run below with your corresponding paths to set ant_home
export ANT_HOME =/ade_autofs/gd29_3rdparty/ANT_1.7.1_GENERIC.rdd/080925/ant
export PATH=/ade_autofs/gd29_3rdparty/ANT_1.7.1_GENERIC.rdd/080925/ant:${PATH}
Try ant build. It should work without any error.
"I agreed with full path issue for the above issue, getting the same exception while folder has access problem"
I have faced the same exception in Macbook. Checked all the configurations JAVA_HOME, ANT_HOME and org.apache.tools.ant.launch.Launcher file in Ant related jars. Finally, found the issue, due to an access problem of the apache-ant folder. I have no admin access, so I moved my setup to the desktop.
$ make vcffilterjs : Compiles OK, with any of these "Linux OS´s" :
Debian 8 Jessie, CentOS 7, Fedora 23, Ubuntu 15.10, PCLinuxOS 2015.
No "ANT_HOME" or "JAVA_HOME" settings required, by using the default installed 'ant' and openjdk.
? Which "Linux OS" are you using ?
antjvarkit

How to create an AppleScript- or Command-file to launch a Java application on Mac OS?

I created a Java application and need to prepare it to run on any OS. For Windows I created a batch file like this launch-win32.bat:
#echo off
javaw -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*;bin/myjar-latest.jar my.package.MyMainClass
For linux I created a shell script like this launch-linux.sh:
#!/bin/sh
java -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*:bin/myjar-latest.jar my.package.MyMainClass
Now I thought MacOS will be quite similar to linux as both are unix based and I asked a friend with a mac to try to run the shellscript to launch my application. But it failed with the following NoClassDefFoundError:
Exception in thread "main" java.lang.NoClassDefFoundError: my/package/MyMainClass
Caused by: java.lang.ClassNotFoundException: my.package.MyMainClass
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
It looks like the syntax of the java command is not correct as the classpath is not properly added to the java programm. My main problem now is the following:
MacOS is not officially supported by Sun/Oracle that's why it's difficult to find some good documentation. (I need the latest JRE 7).
I never used any Mac or don't have any to try out how it could work.
So my questions are now:
How to run java from command line in MacOS, what's the correct syntax? Or why does the command above not work? (For example the main difference between Windows and Linux is using semicolon ; instead of colon : separator for the classpath.)
How should a MacOS script file should be named? .sh or .scpt or .command or is it like in linux that the file ending doesn't matter as long as you chmod +x the script file?
Thanks for any hints.
Okay, after some hours of research it seems there are more than just one answer to this issue(s).
Bash scripts
The simplest way to create scripts in Mac OS seems to be the .command bash script files. They look quite similar to linux shell scripts. Make them executable like shell scripts with chmod +x.
Multiple issues
One reason for the NoClassDefFoundError can be that the default installed Java VM on Mac OS is lower than the needed JRE/JDK which was used compiling the software. Nothing more I can do about that than just telling the user to install the lateste JRE.
Another reason for the NoClassDefFoundError is - and this is quite shocking - that bash scripts in Mac OS don't run from within the same directory as where they are located in but from the user's home directory. The solution is to add a line to the bash script to find out the working directory: cd "$(dirname "$0")" (See also.)
Summary
Windows: launch-win32.bat
#echo off
javaw -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*;bin/myjar-latest.jar my.package.MyMainClass
Linux: launch-linux.sh
#!/bin/sh
java -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*:bin/myjar-latest.jar my.package.MyMainClass
Mac OS: launch-macos.command
#!/bin/bash
cd "$(dirname "$0")"
java -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*:bin/myjar-latest.jar my.package.MyMainClass

Categories

Resources