Why does the GWT compiler require an X server and how to work around it

May 12, 2008 – 20:20 | ajax, maven

Got this error today when trying to build our little GWT application in linux:

CODE:
  1. Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':1' as the value of the DISPLAY variable.
  2.     at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
  3.     at sun.awt.X11GraphicsEnvironment.access$000(X11GraphicsEnvironment.java:95)
  4.     at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:184)
  5.     at java.security.AccessController.doPrivileged(AccessController.java:193)
  6.     at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:173)
  7.     at java.lang.J9VMInternals.initializeImpl(Native Method)
  8.     at java.lang.J9VMInternals.initialize(J9VMInternals.java:192)
  9.     at java.lang.Class.forNameImpl(Native Method)
  10.     at java.lang.Class.forName(Class.java:130)
  11.     at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:101)
  12.     at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1174)
  13.     at com.google.gwt.user.rebind.ui.ImageBundleBuilder.drawBundledImage(ImageBundleBuilder.java:258)
  14.     at com.google.gwt.user.rebind.ui.ImageBundleBuilder.writeBundledImage(ImageBundleBuilder.java:108)
  15.     at com.google.gwt.user.rebind.ui.ImageBundleGenerator.generateImpl(ImageBundleGenerator.java:160)
  16.     at com.google.gwt.user.rebind.ui.ImageBundleGenerator.generate(ImageBundleGenerator.java:76)
  17.     at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:43)
  18.     at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.tryRebind(StandardRebindOracle.java:116)
  19.     at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:61)
  20.     at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:173)
  21.     at com.google.gwt.dev.GWTCompiler$DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(GWTCompiler.java:195)
  22.     at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:105)
  23.     at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.process(AbstractCompiler.java:137)
  24.     at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:329)
  25.     at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.compile(AbstractCompiler.java:74)
  26.     at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.compile(AbstractCompiler.java:162)
  27.     at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.access$600(AbstractCompiler.java:61)
  28.     at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:430)
  29.     at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:65)
  30.     at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.<init>(JavaToJavaScriptCompiler.java:248)
  31.     at com.google.gwt.dev.GWTCompiler.distill(GWTCompiler.java:329)
  32.     at com.google.gwt.dev.GWTCompiler.run(GWTCompiler.java:755)
  33.     at com.google.gwt.dev.GWTCompiler.run(GWTCompiler.java:745)
  34.     at com.google.gwt.dev.GWTCompiler.main(GWTCompiler.java:213)

Apparently the GWT compiler tries to assemble some images into the client package, and in doing so triggers some parts in AWT that require an X display if $DISPLAY is set. There seems to be two solutions:

  1. Make sure $DISPLAY is unset for your build environment.
  2. Define a system property, java.awt.headless=true. The twist here is that if you are using the GWT maven plugin, instead of directly specifying the property on maven's command line, it needs to be defined in the plugin's configuration in the form of:
    <extraJvmArgs>-Djava.awt.headless=true</extraJvmArgs>

Trackback from your site, or follow the comments in RSS.

Post a Comment