Reputation: 659
I have written a macro in ImageJ to run "Measurements" on a list of JPEG image files. I am running the code on a remote linux machine in headless mode using headless.jar.
I get the following excpetion -
> java.awt.HeadlessException: No X11 DISPLAY variable was set, but this
> program performed an operation which requires it.
> at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
> at java.awt.Window.<init>(Window.java:433)
> at java.awt.Frame.<init>(Frame.java:403)
> at ij.plugin.frame.PlugInFrame.<init>(PlugInFrame.java:13)
> at ij.plugin.frame.Editor.<init>(Editor.java:89)
> at ij.plugin.frame.Editor.<init>(Editor.java:85)
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
> at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> at java.lang.Class.newInstance0(Class.java:355)
> at java.lang.Class.newInstance(Class.java:308)
> at ij.IJ.runPlugIn(IJ.java:156)
> at ij.IJ.runPlugIn(IJ.java:141)
> at ij.io.Opener.open(Opener.java:172)
> at ij.IJ.open(IJ.java:1505)
> at ij.macro.Functions.open(Functions.java:2325)
> at ij.macro.Functions.doFunction(Functions.java:141)
How do I override this? Is there a way of preventing ImageJ from opening a graphics environment?
Upvotes: 1
Views: 1269
Reputation: 2976
Not an expert on ImageJ, but it looks like one of the IJ plugins is creating its user interface despite the whole thing being in headless mode (so the problem is not coming from IJ itself). Finding and patching the plugin to behave correctly in headless mode would probably be cumbersome.
There is a solution which works for any application that insists on opening a UI, but can be used through a macro: providing a virtual framebuffer (using xvfb
) and making this the display used by the application.
This should work as long as nothing blocks for user input. Here is some more information for doing this with ImageJ. It's for Fiji, a derived project, but it shows a possible solution using xvfb
which should also work with IJ itself.
Upvotes: 2