RPi java run error - java

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.

Related

How to disable 'headless java mode' to be able to run .jre GUI application using command line on Ubuntu

I have problem with running my java GUI program using cmd on Ubuntu Linux. When I run it using IntelliJ it works just fine, but using cmd breaks it.
From my research I have understood that the problem might be caused by me downloading the 'headless java version'.
So I d like to ask how can I solve this problem. How to mby reinstall it correctly or something that would help.
Thx a lot
I tried:
java -jar TIcTacToe.jar
But, outcome is:
Exception in thread "main" java.awt.HeadlessException:
No X11 DISPLAY variable was set,
or no headful library support was found,
but this program performed an operation which requires it,
at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:166)
at java.desktop/java.awt.Window.<init>(Window.java:553)
at java.desktop/java.awt.Frame.<init>(Frame.java:428)
at java.desktop/java.awt.Frame.<init>(Frame.java:393)
at java.desktop/javax.swing.JFrame.<init>(JFrame.java:180)
at TicTacToe.<init>(TicTacToe.java:7)
at Main.main(Main.java:3)
I am expecting to be able to run my .jre file using cmd.

JVM error: Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

I am using openjdk11 + javafx11 on intellij
Every time I try running a code that requires javafx, I get this error. After some googling around, it seems like it has to do with the display server (xorg, using archlinux kde 5). But I can't find anything that helps me fix the problem.
If anyone could provide some insight to the solution, that would be delightful.
Here's the output I get when I run it:
/usr/lib/jvm/jdk-11.0.1/bin/java -Djava.library.path=/usr/lib/jvm/javafx-sdk-11.0.1/lib --module-path /usr/lib/jvm/javafx-sdk-11.0.1/lib --add-modules=javafx.controls,javafx.fxml -javaagent:/home/rurudu/Intellij/idea-IC-182.4892.20/lib/idea_rt.jar=45449:/home/rurudu/Intellij/idea-IC-182.4892.20/bin -Dfile.encoding=UTF-8 -classpath /home/rurudu/IdeaProjects/HelloFX/out/production/HelloFX:/usr/lib/jvm/javafx-sdk-11.0.1/lib/src.zip:/usr/lib/jvm/javafx-sdk-11.0.1/lib/javafx-swt.jar:/usr/lib/jvm/javafx-sdk-11.0.1/lib/javafx.web.jar:/usr/lib/jvm/javafx-sdk-11.0.1/lib/javafx.base.jar:/usr/lib/jvm/javafx-sdk-11.0.1/lib/javafx.fxml.jar:/usr/lib/jvm/javafx-sdk-11.0.1/lib/javafx.media.jar:/usr/lib/jvm/javafx-sdk-11.0.1/lib/javafx.swing.jar:/usr/lib/jvm/javafx-sdk-11.0.1/lib/javafx.controls.jar:/usr/lib/jvm/javafx-sdk-11.0.1/lib/javafx.graphics.jar sample.Main
(java:16177): Gdk-CRITICAL **: 14:11:28.282: gdk_x11_display_set_window_scale: assertion 'GDK_IS_X11_DISPLAY (display)' failed
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
I was able to solve this by forcing jfx to run using GTK2 by adding this arg to the run command: -Djdk.gtk.version=2
Background: I ran into the exact same error while trying to run the Hello World example for OpenJFX on Fedora running Xwayland and after a bit of searching found an issue logged against openjdk-jfx that describes the same problem. In the comments it suggests forcing jfx to run with gtk2:
We tested it locally and can reproduce a crash (at a different place than you reported), and it looks like it's related to running using GTK3. The default backend was GTK2 for FX in JDK 10 and is GTK3 in FX 11. As a workaround, you can force GTK 2 by running:
java -Djdk.gtk.version=2 ...
Also, you can pass -Djdk.gtk.verbose=true to see what is being used. I also note that we can make JDK 10 crash as well on Wayland by forcing GTK 3.

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.

Deploy JavaFX on Ubuntu server without display

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.

Internal error in eclipse when running java program

Eclipse froze on me earlier today, so I typed "top" into the command prompt and killed it. Now when I try to run a java application, I get this error:
eclipse\plugins\org.eclipse.jdt.debug_3.7.0.v20110509
That's all that shows up under details.
None of my previously working programs run, and I have no clue what this is. I have Eclipse 1.5.0 running 1.6 and 1.7 Java, depending on what program. Thanks for any help.
It is possible that you killed part of the process but not all of it. It is possible that a java process is running with a reference to this job. I would try restarting your computer to see if it will stop whatever process is referencing that jar.
Aside from a restart, then another option would be to use (in linux) pstree, filtered for your user to see if any other jobs are referencing that jar and/or java.
EDIT:
Another path is to look at log files. On linux they are in /var/log. Here's a link in that direction: http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/felog.html

Categories

Resources