Fix running in background without X11

+2 votes
asked Nov 16, 2013 in Bug by Pander (780 points)
When I run PlantUML without a GUI in as a background process in a shell that doesn't have access to X11, I get this error:

No protocol specified
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
    at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
    at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
    at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:110)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:102)
    at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
    at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1190)
    at net.sourceforge.plantuml.EmptyImageBuilder.<init>(Unknown Source)
    at net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek.<clinit>(Unknown Source)
    at net.sourceforge.plantuml.cucadiagram.CucaDiagram.exportDiagramInternal(Unknown Source)
    at net.sourceforge.plantuml.UmlDiagram.exportDiagram(Unknown Source)
    at net.sourceforge.plantuml.PSystemUtils.exportDiagramsCuca(Unknown Source)
    at net.sourceforge.plantuml.PSystemUtils.exportDiagrams(Unknown Source)
    at net.sourceforge.plantuml.SourceFileReader.getGeneratedImages(Unknown Source)
    at net.sourceforge.plantuml.Run.manageFileInternal(Unknown Source)
    at net.sourceforge.plantuml.Run.processArgs(Unknown Source)
    at net.sourceforge.plantuml.Run.manageAllFiles(Unknown Source)
    at net.sourceforge.plantuml.Run.main(Unknown Source)
 

A workaround is to run it on a machine with X11 running and have the shell that is starting have access to X11. For example, running it as "su - anotherusername [after logging in] java -jar plantuml.jar test.txt" will give the same error unless you do "xhost +" before. If you run "xhost -" the error will happen again.

1 Answer

+2 votes
answered Nov 16, 2013 by plantuml (294,960 points)

Hello,

Did you try the following option:

/usr/bin/java -Djava.awt.headless=true -jar /data/PlantUml/plantuml.jar ...

See http://plantuml.sourceforge.net/faq.html#headless

 

commented Nov 16, 2013 by Pander (780 points)
Yes that works but I would expect that by default if I don't use any GUI. Can that be integrated in PlantUML?
commented Nov 17, 2013 by plantuml (294,960 points)
This has been implemented in version 7986. But no tests has been done, so feedback is appreciate.
commented Oct 29, 2014 by anonymous
Using net.sourceforge.plantuml:plantuml:8000

Same problem arises:

Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable..
->>  191 | forName   in java.lang.Class
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    102 | createGE  in java.awt.GraphicsEnvironment
|     81 | getLocalGraphicsEnvironment in     ''
|   1182 | createGraphics in java.awt.image.BufferedImage
|     58 | <init> .  in net.sourceforge.plantuml.EmptyImageBuilder
|    167 | createImage in net.sourceforge.plantuml.graphic.GraphicStrings
|    145 | exportDiagram in     ''
|     96 | exportDiagram in net.sourceforge.plantuml.PSystemError
|    110 | generateImage in net.sourceforge.plantuml.SourceStringReader
|     92 | generateImage in     ''
|     66 | asStream  in grails.plugin.umlclassdiagram.PlantUmlService

The
-Djava.awt.headless=true
option fixes this, as suggested above.
commented Oct 29, 2014 by Pander (780 points)
Now it works. Can't remember if I used that option when I reported this. Thanks.
commented Nov 24, 2016 by Pander (780 points)
When running plantuml from the command line (/usr/bin/plantuml) it doesn't matter. When X is available, a logo is shown. When X is not available, no logo is shown.

Perhaps add an option to this that logo is not shown when run in shell in X?
commented Nov 25, 2016 by plantuml (294,960 points)
See http://plantuml.sourceforge.net/qa/?qa=3822/splash-screen-when-running

You can use -splash:no option flags. For example, :

java -splash:no -jar plantuml.jar -version
commented Sep 4, 2020 by wolfgang_fahl (160 points)
Even with the latest version 1.2020.00 the problem showed up and i need to use the workaround with -Djava.awt.headless=true
...