jlesage / docker-baseimage-gui

A minimal docker baseimage to ease creation of X graphical application containers
MIT License
1.2k stars 179 forks source link

running java application does not work #26

Closed calgara12 closed 9 months ago

calgara12 commented 5 years ago

Hey, I'm trying to run Nitro Explorer 3 inside this container. The container always exits immediately throwing the error:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
        no swt-gtk-4335 in java.library.path
        no swt-gtk in java.library.path
        Can't load library: /dev/null/libswt-gtk-4335-64.so
        Can't load library: /dev/null/libswt-gtk-64.so

        at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
        at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
        at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
        at org.eclipse.swt.internal.Converter.wcsToMbcs(Unknown Source)
        at org.eclipse.swt.internal.Converter.wcsToMbcs(Unknown Source)
        at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
        at gui.MainWindow.open(MainWindow.java:65)
        at gui.MainWindow.main(MainWindow.java:55)
        ... 5 more

I have tried alpine, debian and ubuntu, i always get this message.

My basic approach is this: Inside the Dockerfile

  1. I copy the .jar file to the /opt/nitro/ directory
  2. Install java
  3. Copy startapp.sh to /

Inside the startapp.sh: /usr/bin/java -jar /opt/nitro/myapp.jar

A lot of hours have gone into this and I don't know what I could possibly do to make this work. If you could assist me, that would be awesome.

Thanks!

jlesage commented 5 years ago

Did you install the package which provides libswt-gtk*.so libraries?

calgara12 commented 5 years ago

Yeah, my Dockerfile looks like:

FROM jlesage/baseimage-gui:ubuntu-18.04

# Install xterm.
RUN apt-get update && apt-get install -y openjdk-8-jre libswt-gtk*

# Copy the start script.
COPY nitro.jar /app/
COPY startapp.sh /startapp.sh

# Set the name of the application.
ENV APP_NAME="Nitroexplorer"
jlesage commented 4 years ago

Maybe you could try to install it on a normal Linux installation to see how the app is started. They are often started with a couple of java options...

David-Lor commented 4 years ago

I'm having a similar problem: I'm getting errors related to /dev/null as well. I'm trying to make an image that loads Eclair GUI, and (part of) the traceback is the following:

Loading library prism_es2 from resource failed: java.io.IOException: Can not create cache at /dev/null/.openjfx/cache/[168/1841]
java.io.IOException: Can not create cache at /dev/null/.openjfx/cache/11.0.2                                                    
        at com.sun.glass.utils.NativeLibLoader.cacheLibrary(NativeLibLoader.java:233)                                          
        at com.sun.glass.utils.NativeLibLoader.installLibraryFromResource(NativeLibLoader.java:203)                             
        at com.sun.glass.utils.NativeLibLoader.loadLibraryFromResource(NativeLibLoader.java:185)                                        at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:157)                                    
        at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:52)                       
        at com.sun.prism.es2.ES2Pipeline.lambda$static$0(ES2Pipeline.java:68)                                                   
        at java.base/java.security.AccessController.doPrivileged(Native Method)                                  
        at com.sun.prism.es2.ES2Pipeline.<clinit>(ES2Pipeline.java:50)                                                          
        at java.base/java.lang.Class.forName0(Native Method)                                       
        at java.base/java.lang.Class.forName(Class.java:315)                             
        at com.sun.prism.GraphicsPipeline.createPipeline(GraphicsPipeline.java:187)
        at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:91)              
        at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)            
        at java.base/java.lang.Thread.run(Thread.java:834)                                                                      
Loading library prism_sw from resource failed: java.io.IOException: Can not create cache at /dev/null/.openjfx/cache/11.0.2
java.io.IOException: Can not create cache at /dev/null/.openjfx/cache/11.0.2                                                    
        at com.sun.glass.utils.NativeLibLoader.cacheLibrary(NativeLibLoader.java:233)                                           
        at com.sun.glass.utils.NativeLibLoader.installLibraryFromResource(NativeLibLoader.java:203)           
        at com.sun.glass.utils.NativeLibLoader.loadLibraryFromResource(NativeLibLoader.java:185)                                
        at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:157)                                    
        at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:52)                  
        at com.sun.prism.sw.SWPipeline.lambda$static$0(SWPipeline.java:42)                                                      
        at java.base/java.security.AccessController.doPrivileged(Native Method)                                                 
        at com.sun.prism.sw.SWPipeline.<clinit>(SWPipeline.java:41)                                                             
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:315)
        at com.sun.prism.GraphicsPipeline.createPipeline(GraphicsPipeline.java:187)
        at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:91)
        at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)
        at java.base/java.lang.Thread.run(Thread.java:834)

As we can see, it also uses /dev/null as a directory. I'm currently trying on the ubuntu-18.04 tag with openjdk-11, but also tried debian-9 and manually downloading openjdk-11 from AdoptOpenJDK.

I tried running the JAR on a Docker container with Lubuntu + VNC and started correctly with no errors.

So, It might have something to do with some Java option, maybe is trying to write on the /home directory and by some reason it defaults it to /dev/null? Kinda weird.

David-Lor commented 4 years ago

@calgara12 The problem seems to be that this image uses a user with no HOME route (more like the home set to /dev/null), which causes these errors (check this: https://github.com/jlesage/docker-baseimage-gui#home-environment-variable).

Theorically we can set the home in Java like this (here I show my startapp.sh file):

#!/bin/sh

set -ex

HOME="/tmp"

_JAVA_OPTIONS="-Duser.home=${HOME}"  exec java -verbose -jar /eclair.jar

In my case another errors show up, but at least is not showing problems related with /dev/null. Maybe it works for you.

(Haven't tried yet setting the HOME env var before running the java command)

Loader23 commented 4 years ago

similar here: The Application is using eclipse and trys to write to /dev/null/.eclipse... I tried changing Home to /config but no luck. Any Ideas how I can make him not using /dev/null?

masterfwadmin commented 4 years ago

For openjfx cache, I had same issue. This option fixes it...

-Djavafx.cachedir=/tmp

mitchweaver commented 3 years ago
java -jar \
    -Djavafx.cachedir=/tmp \
    -Duser.home=/tmp \

This should fix your issues

jlesage commented 9 months ago

Closing this issue. Please re-open if needed.