Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop BufferedImage.getGraphics() opening an X11 device?

I have the following code for creating raster images.

    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
    Graphics g = img.getGraphics();
    g.setColor(backgroundColour);       
    g.fillRect(0, 0, width, height);

This runs on my Windows machine and on a local Ubuntu machine, but when transferred to a server attempts to call an X11 server, with the stack trace shown . How can I prevent this?

    Exception in thread "main" java.lang.InternalError: Can't connect to X11
window server using 'localhost:10.0' as the value of the DISPLAY variable.
        at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at
sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:62)
        at
sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:178)
        at java.security.AccessController.doPrivileged(Native Method)
        at
sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:142)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:190)
        at
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
        at
java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1164)
        at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1154)
        at
org.xmlcml.cml.converters.molecule.fragments.Cml2PngTool.renderMolecule(Cml2PngTool.java:94)
        at
org.xmlcml.cml.converters.molecule.fragments.Cml2PngTool.renderMolecule(Cml2PngTool.java:61)
        at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.add2DCoordsAndRender(FragmentGenerator.java:180)
        at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.write2dImage(FragmentGenerator.java:169)
        at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.output2dImages(FragmentGenerator.java:486)
        at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.generateMoieties(FragmentGenerator.java:443)
        at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.createMoietiesAndFragments(FragmentGenerator.java:125)
        at
org.xmlcml.cml.converters.molecule.fragments.CML2FragmentConverter.convert(CML2FragmentConverter.java:47)
        at
org.xmlcml.cml.converters.AbstractConverter.process(AbstractConverter.java:1067)
        at
org.xmlcml.cml.converters.AbstractConverter.processInputFile(AbstractConverter.java:1060)
        at
org.xmlcml.cml.converters.AbstractConverter.runArgs(AbstractConverter.java:1016)
        at
org.xmlcml.cml.converters.molecule.fragments.CML2FragmentConverter.main(CML2FragmentConverter.java:74)
like image 703
peter.murray.rust Avatar asked Jan 23 '14 08:01

peter.murray.rust


1 Answers

Specify headless from the command line:

-Djava.awt.headless=true

Or from code:

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

See http://www.oracle.com/technetwork/articles/javase/headless-136834.html for more info.

like image 55
Harald K Avatar answered Nov 03 '22 00:11

Harald K