Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not initialize class sun.awt.X11GraphicsEnvironment on Solaris

I am running into this error while running my installer on a Solaris machine:

Installing...
-------------

 [==================|==================|==================|==================]
 [---Invocation of this Java Application has caused an InvocationTargetException. This application will now exit. (LAX)

Stack Trace:
java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:186)
        at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:102)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
        at sun.awt.X11FontManager.isHeadless(X11FontManager.java:487)
        at sun.awt.X11FontManager.getFontPath(X11FontManager.java:767)
        at sun.font.SunFontManager.getPlatformFontPath(SunFontManager.java:3288)
        at sun.font.SunFontManager$11.run(SunFontManager.java:3314)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.font.SunFontManager.loadFonts(SunFontManager.java:3310)
        at sun.awt.X11FontManager.loadFonts(X11FontManager.java:439)
        at sun.font.SunFontManager.findFont2D(SunFontManager.java:2347)
        at sun.font.SunFontManager.findFont2D(SunFontManager.java:2285)
        at java.awt.Font.getFont2D(Font.java:498)
        at java.awt.Font.getFamily(Font.java:1187)
        at java.awt.Font.getFamily_NoClientCode(Font.java:1161)
        at java.awt.Font.getFamily(Font.java:1153)
        at ZeroGrs.a(DashoA10*..)
        at ZeroGrs.a(DashoA10*..)
        at ZeroGrs.a(DashoA10*..)
        at ZeroGrs.a(DashoA10*..)
        at ZeroGrs.a(DashoA10*..)
        at ZeroGrs.a(DashoA10*..)
        at com.zerog.ia.installer.actions.InstallUninstaller.a(DashoA10*..)
        at com.zerog.ia.installer.actions.InstallUninstaller.d(DashoA10*..)
        at com.zerog.ia.installer.actions.InstallUninstaller.installSelf(DashoA10*..)
        at com.zerog.ia.installer.InstallablePiece.install(DashoA10*..)
        at com.zerog.ia.installer.actions.InstallDirectory.install(DashoA10*..)
        at com.zerog.ia.installer.actions.InstallDirectory.install(DashoA10*..)
        at com.zerog.ia.installer.InstallablePiece.install(DashoA10*..)
        at com.zerog.ia.installer.GhostDirectory.install(DashoA10*..)
        at com.zerog.ia.installer.InstallablePiece.install(DashoA10*..)
        at com.zerog.ia.installer.Installer.install(DashoA10*..)
        at com.zerog.ia.installer.LifeCycleManager.b(DashoA10*..)
        at com.zerog.ia.installer.LifeCycleManager.a(DashoA10*..)
        at com.zerog.ia.installer.Main.main(DashoA10*..)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at com.zerog.lax.LAX.launch(DashoA10*..)
        at com.zerog.lax.LAX.main(DashoA10*..)

I tried configuring JAVA_OPTS with -Djava.awt.headless=true but it doesn't work!

Any has other solution to the issue?

like image 759
Deka Avatar asked Jan 15 '14 07:01

Deka


3 Answers

Solved the issue. It was my profile, where I have set my DISPLAY to one host, which is not alive. I have set it correctly and it worked.

$ export DISPLAY=

Or

$ unset DISPLAY

like image 60
Deka Avatar answered Oct 17 '22 13:10

Deka


Try running this code in a constructor of a servlet

System.setProperty("java.awt.headless", "true"); 

or

Use this parameter in the startup script of the server:

-Djava.awt.headless=true

Here is an example of this problem documented and explaned in Apache POI when you want to create a sheet with auto size columns.

like image 31
Edgard Leal Avatar answered Oct 17 '22 14:10

Edgard Leal


Actually,

-Djava.awt.headless=true

Does not fix the issue, it sidesteps it. The problem is the application you are trying to run want to run with a UI in XWindows. This error is saying the Java equivalent of 'dll not found' or '.so not found'. The library required to actually do this isn't present in the JVM classpath you are using.

The problem is you're using OpenJDK (or some other version of Java like Jikes) and the awt was one of the parts of Java that could not be open sourced for licensing reasons. So, this class doesn't exist on purpose and never will in OpenJDK

By declaring

-Djava.awt.headless=true

You are making it run in commandline mode and not all apps can do this. In your case, you got away with with. The only way to actually fix this issue is to get that class and all it's dependent classes in your classpath. The simplest way to do that is to switch to the sun JRE.

like image 16
Christian Bongiorno Avatar answered Oct 17 '22 14:10

Christian Bongiorno