JavaCall.jl
JavaCall.jl copied to clipboard
Avoiding Exceptions during automatic testing
JavaCall throws a java.awt.HeadlessException
in Linux systems due to a missing "X11" display specification, when Git-Hub automatic testing is performed. Does anyone know how to avoid this? Also on Mac the tests fail due to a missing java installation. Are there easy fixed for this?
For Mac, set the JAVA_HOME
environmental variable to tell JavaCall where to find Java. Where are you getting Java for Mac from?
I will get around to setting GitHub Actions CI here soon.
I would look into something like https://github.com/marketplace/actions/gabrielbb-xvfb-action
For Mac, set the
JAVA_HOME
environmental variable to tell JavaCall where to find Java. Where are you getting Java for Mac from? Thanks for the hints. Would be great, if the GitHub Actions CI can be convinced to deal with this. These tests work well on the Windows virtual machine (which seems to include a java installation) but they fail for the named reasons on Linux and Mac.
For headless Java, set java.awt.headless=true
If you need to install Java, then use something like https://github.com/actions/setup-java
Thanks. This is in my ci.yml
file in .github\workflows
, but it seems to have no positive effect on the tests.
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
distribution: 'adopt' # See 'Supported distributions' for available options
java-version: '11'
The issue is that JavaCall.jl does not know where adopt put Java, so you need to set the JAVA_HOME environmental variable where it got installed.
The problem seems to be the X-Windows system under Linux. GitHub actions works pretty well. Even the installation of the x-windows system seems to run through but it always stops when trying to connect to DISPLAY=:0.0
or any other number I tried.
I disabled the tests on Linux and Mac for now, since I couldn't get it to work. This was the code, which did not work when linux and mac were enabled:
https://github.com/RainerHeintzmann/View5D.jl/blob/master/.github/workflows/ci.yml
For headless Java, set java.awt.headless=true
Did you try aviks's comment above?
Concretely,
using JavaCall
JavaCall.addOpts("-Djava.awt.headless=true")
# Configure classpath here
JavaCall.init()
More details on that here: https://www.oracle.com/technical-resources/articles/javase/headless.html
Thanks for the hint! This causes other problems, but they are possibly fixable in my Java code. The headless mode is understandably unhappy to report about its screensize:
Exception in thread "main" java.awt.HeadlessException
at sun.awt.HeadlessToolkit.getScreenSize(Unknown Source)
at view5d.View5D.Start5DViewer(View5D.java:532)
start viewers: Error During Test at C:\Users\pi96doc\Documents\Programming\Julia\View5D.jl\test\runtests.jl:9
Got exception outside of a @test
JavaCall.JavaCallError("Error calling Java: java.awt.HeadlessException")
I will fix this...
Bad news: Even a simple new
of a java.applet.Applet
object causes the same exception. Rewinding ....
Aren't applets deprecated as of Java 9? I'm not really sure if there is any way to still use them in a modern browser.
https://www.oracle.com/technetwork/java/javase/migratingfromapplets-2872444.pdf
I see View5D
extends java.applet.Applet
so I could see how that might be a complicated to extricate.
Thanks for the hint. I wasn't really aware of this deprecation. So I changed the main class from extending Applet
to Container
and fixed a few related issues and got it working again, but then the next problem pops up. Looks a bit like a never-ending story with headless graphics:
Exception in thread "main" java.awt.HeadlessException
at java.awt.GraphicsEnvironment.checkHeadless(Unknown Source)
at java.awt.Label.<init>(Unknown Source)
at java.awt.Label.<init>(Unknown Source)
at view5d.ImgPanel.<init>(ImgPanel.java:199)
at view5d.View5D.initLayout(View5D.java:867)
at view5d.View5D.Prepare5DViewer(View5D.java:750)
at view5d.View5D.Start5DViewer(View5D.java:518)
at view5d.View5D.Start5DViewer(View5D.java:544)
See https://www.oracle.com/technical-resources/articles/javase/headless.html
For Linux, this can create a virtual X server: https://github.com/marketplace/actions/gabrielbb-xvfb-action