Deploy JavaFX on Ubuntu server without display - java

I'm developing a JavaFX application using jdk1.7.0_51 on Mac OS X (10.9.1) in Netbeans. I can run it without a problem and after a clean build I can also launch the jar from the dist/ folder.
Now I want to deploy this on a 64 bit Ubuntu 13.04 server. I've had a lot of issues doing this but have finally set up the server to have the correct JRE, fonts and libraries. Running the jar resulted in errors going way deeper than my code (going to UnsatisfiedLinks to native libraries where MACOS was mentioned) so I figured it would be best to package my app on Ubuntu itself. I ended up installing NetBeans to make a new (native) JavaFX project and uploaded the src/ and lib/ folders from my machine using sftp. Running the code through the reconstructed project in NetBeans works fine, though I get a warning in the console during run:
libGL error: failed to load driver: swrast
libGL error: Try again with LIBGL_DEBUG=verbose for more details.
Prism-ES2 Error : GL_VERSION (major.minor) = 1.4
Regardless, the application DOES run. After a clean build, I can similarly run the jar from the dist/ folder. The same warning appears in the terminal but then the application launches.
However, if I ssh to the server without the -X flag and try to run the application, I get the following:
Failed in XOpenDisplay
(java:29341): Gtk-WARNING **: cannot open display:
However, my application does not have a UI. It simply uses JavaFX for the WebEngine (this is required and can not be changed). I was wondering if anyone knows if (and if so, how) it's possible to launch my JavaFX jar without a display (to just run as a daemon on the server).
Kind regards,
Warkst
EDIT:
I've tried some things described here: Java Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable
You need to specify the -Djava.awt.headless=true parameter at startup time.
(Assuming I'm doing it right with the command java -Djava.awt.headless=true -jar MyApp.jar), this yielded no results (the same errors occur).
export DISPLAY=:0
Still no result, though the error obviously changed slightly to now read:
(java:30765): Gtk-WARNING **: cannot open display: :0
Then finally I also tried the following:
unset DISPLAY
This resulted in the original error (where obviously DISPLAY was not set).

I don't think JavaFX 2.x supports running in a headless mode. I don't know of any workaround.
For further info see the JavaFX issue tracker feature request: RT-34241 Use of WebEngine in a headless system, currently scheduled for implementation for Java 9.

I had almost the same problem
Failed in XOpenDisplay
(java:2593): Gtk-WARNING **: cannot open display:
while running unit tests for my JavaFX application in headless Ubuntu docker container on Travis CI.
The solution is installing X Virtual Framebuffer (xvfb) in the container to imitate a display presents via the container configuration change in .travis.yml
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
This allows JavaFX successfully initialize it's core and create JavaFX components without actually showing them on screen.
See details of this solution in article Using xvfb to Run Tests That Require a GUI

Running dbus-update-activation-environment --systemd DISPLAY XAUTHORITY in that shell before launching the UI app fixed this issue for me.

Related

Container did not start during docker stack deploy, could not find or load main class, unable to diagnose further

I am helping on a project which consists of a Docker stack with a bunch of services all working together. All of them start except for one.
Using docker service ps my-service --no-trunc gives me: task: non-zero exit(1)
Using docker service logs my-service gives me: Error: could not find or load main class
This particular container has a Java application running in support of a NodeJS server. After npm install, npm run init, npm run build, and mvn clean install, I was able to successfully build the Docker image. No errors.
However, now it's not actually starting. I can't figure out how to diagnose it any further. The error message doesn't tell me a whole lot. The Java code is old, but it should work, I never touched it.
Mainly, I don't know where to progress from here. Google searches turn up only stuff where they have access to a lot more debugging information, and I just don't have enough to go on. Java is not my strength. What am I missing?
UPDATE 3/21/19: Thanks to #VinDev, I was able to get some more detailed information (it should've been obvious to me to try this, but it's good to learn).
Used docker run --name TestMyContainer -it my-image bash to start up the container, then ran the normal starting command for the container in the stack, which is catalina.sh run. That gave me the following output:
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /docker-java-home/jre
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Error: Could not find or load main class
UPDATE #2 3/21/19: I was able to solve the issue. I should've included more information: I'm on a Windows machine, but making Linux containers. I found the answer here: Tomcat startup - Error: Could not find or load main class
Windows had reverted the setenv.sh file to CRLF EOL. I changed it back in Visual Studio Code, ran the container again, and everything works!
Run docker service ls to see if the service shows up ...
also run docker service inspect my-service
This should give you a container id you can use to get the logs
docker logs CONTAINER_ID
You can also run the container by itself
docker run IMAGE_NAME
to see the result of just running it as a container
/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Seems it can't find bootstrap.jar or tomcat-juli.jar
Maybe not being copied by Dockerfile?
I added this to the original post, but adding it here as well to properly mark the question as answered:
I was able to solve the issue. I should've included more information: I'm on a Windows machine, but making Linux containers. I found the answer here: Tomcat startup - Error: Could not find or load main class
Windows had reverted the setenv.sh file to CRLF EOL. I changed it back in Visual Studio Code, ran the container again, and everything works!

RPi java run error

My java -version is 1.8.0. What am I doing wrong, I cant run my basic hello world gui without this as I'm trying to use it similar to a "kiosk" with no desktop environment and JUST this.
Error: missing 'server' JVM at '/usr/lib/jvm/java-8-openjdk-armhf/jre/lib/arm/server/libjvm.so'.
Please install or use the JRE or JDK that contains these missing components.
E: /etc/ca-certificates/update.d/jks-keystore exited with code 1.
done.
Errors were encountered while processing:
ca-certificates-java
openjdk-8-jre-headless:armhf
openjdk-8-jre:armhf
E: Sub-process /usr/bin/dpkg returned an error code (1)
It looks like you are running from a RaspberryPi and the jdk is headless then you can not create a gui on the py without doing it remote... but you can run an remote Xserver and display a GUI on that.
Swing applications are headfull so to speak and need a graphical interface. This will not work unless you pipe it over an X enabled ssh connection to another machine with an XServer. As you are trying to start a Swing appliation in a console without a Graphical interface is will surely fail.

How to execute Carrot2 Document Clustering server

I downloaded the Carrot2 Document clustering server build 3.15.0 for Mac. The read me file says:
The DCS requires a Java Runtime Environment (JRE) version 1.7.0 or later. To
run the DCS, execute the 'dcs' script and point your browser at
http://localhost:8080 for further instructions.
Mac OS Sierra doesn't make it easy, but I got 1.8.0_112 installed.
The problem is that I don't know how to execute the 'dcs' script.
There are .cmd, .sh, .war, and .jar files. I wasn't sure which of those to work with. I thought .jar looked promising, so I followed some of this thread and tried this in a terminal window:
java -jar invoker.jar
I cd-ed to the correct directory, but it just says Provide main class, but I'm not sure what or where that is.
Can anybody provide instructions or a link to how to do this?
Use the dcs.sh (on Linux/Mac) and dcs.cmd (on Windows) to start the server. The scripts will set some extra options for the JVM and then start the DCS. In case of any problems, append the -v option to see diagnostic output.

ScenicView 8.6.0 not finding JavaFX application

Currently using JDK 1.8 update 92 (32-bit). Why might ScenicView not be able to find my JavaFX application when launched from the jar, or as a -javaagent: parameter?
If I launch my JavaFX application, and then launch ScenicView from the jar file, it just sits there trying to find something to connect to. I have the -debug option set on the command line and all I get is this :-
Platform running
Launching ScenicView v8.0.0
Startup done
Creating server
Server done
Number of running Java applications found: 0
0 JavaFX applications found
I've tried starting ScenicView both as an "external tool" from IntelliJ (with the correct JVM specified), and just from the command line. Same result.
The -javaagent method does not seem to work either. If I add the jar as a -javaagent parameter to my application, as per the documentation, I just get this error on startup:
Exception in thread "scenic-view-boot" java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
at javafx.application.Platform.runLater(Platform.java:83)
at org.scenicview.ScenicView.lambda$premain$34(ScenicView.java:122)
at java.lang.Thread.run(Thread.java:745)
The only method of launching that works is to add the ScenicView jar to my application classpath and embed a launch into my application source like this
ScenicView.show(mainScene);
Which isn't as convenient as being able to just fire it up as a standalone tool when I need it.
This used to work perfectly. I can dig out some older JDK versions and see if it worked with an earlier jvm (update 77 exhibits exactly the same problem), but in the meantime, is there some way of getting more detailed logging out so I can try and find the problem?
It seems that it is bug in ScenicView startup in agent mode. I opened issue and propose PR to fix it.

Remote Debugging GUI Java Application (swing) in NetBeans 8

I setup the remote debugging in NetBeans IDE between 2 Linux systems. Remote debugging an application that does not have a GUI works ok, but I am getting this error when I try to remote debug an application that has swing GUI:
Exception in thread "AWT-EventQueue-0"
java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
I would appreciate any suggestion!
NetBeans output window:
ant -f /home/toma/NetBeansProjects/GUIFormExamples -Dremote.platform.password=***** -Dremote.platform.rp.target=linux-15 -Dremote.platform.java.spec.ver=17 -Dremote.platform.rp.filename=linux -Ddebug.class=Antenna -Dnb.internal.action.name=debug debug-remote
init:
Deleting: /home/toma/NetBeansProjects/GUIFormExamples/build/built-jar.properties
deps-jar:
Updating property file: /home/toma/NetBeansProjects/GUIFormExamples/build/built-jar.properties
compile:
Copying 1 file to /home/toma/NetBeansProjects/GUIFormExamples/build
Copy libraries to /home/toma/NetBeansProjects/GUIFormExamples/dist/lib.
To run this application from the command line without Ant, try:
java -jar "/home/toma/NetBeansProjects/GUIFormExamples/dist/GUIFormExamples.jar"
jar:
Connecting to 192.168.1.122:22
Connecting to 192.168.1.122:22
cmd : mkdir -p '/home/toma/NetBeansProjects//GUIFormExamples/dist'
Connecting to 192.168.1.122:22
done.
profile-rp-calibrate-passwd:
Connecting to 192.168.1.122:22
cmd : cd '/home/toma/NetBeansProjects//GUIFormExamples'; '/usr/lib/jvm/j2sdk1.7-oracle/jre/bin/java' -Xdebug -Xrunjdwp:transport=dt_socket,address=localhost:39245 -Dfile.encoding=UTF-8 -jar /home/toma/NetBeansProjects//GUIFormExamples/dist/GUIFormExamples.jar
Exception in thread "AWT-EventQueue-0"
java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:207)
at java.awt.Window.(Window.java:535)
You need to add DISPLAY environment variable export to your ant build xml file. I have blogged about this issue and it's solution on my blog
For my project there was a target named "-copy-to-remote-platform" and two macros in it: "runwithpasswd" and "runwithkey" in ANT build xml file which required some modifications.
I have added "export DISPLAY=:0;" to last sshexec commands in each of the aforementioned macros so that they both looked like this:
<sshexec host="${remote.platform.host}" port="${remote.platform.port}" username="${remote.platform.user}" password="${remote.platform.password}" trust="true" usepty="true"
command="export DISPLAY=:0; cd '${remote.project.dir}'; ${remote.platform.exec.prefix}'${remote.java.executable}' #{additionaljvmargs} -Dfile.encoding=${runtime.encoding} ${run.jvmargs} ${run.jvmargs.ide} -jar ${remote.dist.jar} ${application.args}"/>
Mind the "export DISPLAY=:0;" on the beginning of the "command" attribute.
You need to use X11 forwarding, to make the GUI on the remote computer visible on your computer (or otherwise give a valid DISPLAY environment variable, so the GUI can be displayed somewhere). This is a Linux configuration issue, Java is just complaining that it can't create a GUI, because (as far as it knows) there is no screen available.
Success! It is not as easy as it should be, but it works.
In NetBeans (I used version 8) create a new Java Platform for remote debugging: Tools -> Java Platforms -> Add Platform -> Remote Java Standard Edition -> ... (for more info see this link: https://netbeans.org/kb/docs/java/javase-embedded.html). Press the drop-down menu on the Debug Icon (debug-remote) and watch the output window.
That works well if the program does not have a GUI.
If the program has a GUI, I get this error: "java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it"
Even if the program has a GUI, the steps above help, because it automatically deploys your program on the remote server.
To debug the GUI, the workaround I found, is to remotely connect to the server using ssh or VNC and run the java program in debug mode:
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=y -jar "/MyPath/Program.jar".
Java VM should pause the program and wait for NetBeans debugger to connect.
In NetBeans, set a break point in the program and attach to the remote process: Debug -> Attach Debugger -> Java Debugger, SocketAttach, dt_socket, IP address of the server, Port: 4000 -> OK
Later on you can just press the drop-down menu on the Debug Icon (Attach to ...) to start debugging.
The program should run to the break point and pause execution. You should have full control over the GUI on the programming computer but the program is executed on the server.
This is very useful when debugging Java programs on single board computers like BeagleBone Black or Raspberry PI that do not have enough horsepower to run NetBeans. This is essential when the single board computer is used in a robotics application and it needs to receive sensor inputs and control motors.
The Solution:
Go to Run → Set Project Configuration → Customize..
Click Manage Platforms
Select the remote configuration for your RPI
On right sight go to Exec Prefix and write startx in it.
Problem is that NetBeans single-quotes everything that you put into the Exec Prefix field. So you can put in your own single-quotes to construct a valid bash command. Imagine you have a VNC virtual desktop at display :2.0, you can trick it out with
export' DISPLAY=:2.0;'sudo
Finally this will result in a working bash command string with a quoted export and a quoted sudo (which does no harm). If you don't want your program to run in superuser mode, change it to
export' DISPLAY=:2.0;sudo -u 'pi
I found only the sudo command as a working way to cope with these single quotes.

Categories

Resources