Dear all,
I would like to run ImageJ in a headless environment (no Desktop, no X.org, no Aqua, just plain old tty) to take advantage of a cluster. According to the ij.ImageJ class, one can run macros without GUI like: -batch path [arg] Runs a macro in batch (no GUI) mode, passing it an optional argument. ImageJ exits when the macro finishes. I setup a simple macro in the file macros/any.txt : macro 'Test' { setBatchMode(true); print("Hello"); for (i=0; i<10; i++) { print(i); } } So I run: $ java -classpath ij.jar ij.ImageJ macros/any.txt When run in an xterm (a desktop environment exists), it prints without problems to the xterm. But when run from a tty, nothing prints except one like: Gtk-warning **: cannot open display Then I tried to use the RunMacro class from rsb.info.nih.gov/ij/plugins/download/jars/macro-runner.zip with the command: $ java -classpath ij.jar:. RunMacro macros/any.txt From an xterm, again, no problem. From a tty I get a nasty class loader exception: Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: RunMacro at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0) at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.5.0.0) at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0) at java.lang.Class.forName(java.lang.String) (/usr/lib/libgcj.so.5.0.0) at gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.5.0.0) at _Jv_ThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.5.0.0) at _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/libgcj.so.5.0.0) at __gcj_personality_v0 (/home/cardona/bin/ImageJ/java.version=1.4.2) at __libc_start_main (/lib/tls/libc-2.3.4.so) at _Jv_RegisterClasses (/home/cardona/bin/ImageJ/java.version=1.4.2) Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in [file:./, file:ij.jar, file:/usr/share/java/libgcj-3.4.5.jar, file:./, core:/] at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0) at gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0) at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.5.0.0) at _Jv_FindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0) at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0) at _Jv_BytecodeVerifier.verify_instructions_0() (/usr/lib/libgcj.so.5.0.0) at _Jv_VerifyMethod(_Jv_InterpMethod) (/usr/lib/libgcj.so.5.0.0) at _Jv_PrepareClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0) at _Jv_WaitForState(java.lang.Class, int) (/usr/lib/libgcj.so.5.0.0) at java.lang.VMClassLoader.linkClass0(java.lang.Class) (/usr/lib/libgcj.so.5.0.0) at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0) ...9 more So: is this a java limitation (that it needs a display), or is it an ImageJ limitation? Sounds like a java limitation. Is there any workaround? Any java virtual machines that can run headless? I have found that one can specify the -Djava.awt.headless=true in the command line, but that doesn't help ImageJ in any way when run from a tty. Thanks for any ideas. Albert |
I get the same behavior:
Exception in thread "main" java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. at java.awt.GraphicsEnvironment.checkHeadless(Unknown Source) at java.awt.MenuComponent.<init>(Unknown Source) at java.awt.MenuItem.<init>(Unknown Source) at java.awt.MenuItem.<init>(Unknown Source) at java.awt.Menu.<init>(Unknown Source) at java.awt.Menu.<init>(Unknown Source) at ij.Menus.addMenuBar(Menus.java:87) at ij.IJ.init(IJ.java:333) at ij.IJ.runMacroFile(IJ.java:93) at ij.ImageJ.main(ImageJ.java:471) With this error info, it should be possibel to customize ij to run gui free. kurt On 4 Oct 2006, at 16:46, Albert Cardona wrote: > -Djava.awt.headless=true *--*--*--*--*--*--*--*--*--*--*--*--*--* University of Sheffield Academic Neurology Unit Division of Genomic Medicine E Floor, Medical School Beech Hill Road Sheffield S10 2RX United Kingdom Tel: ++44 (0) 114 271 2473 Fax: ++44 (0) 114 226 1201 Email: [hidden email] *--*--*--*--*--*--*--*--*--*--*--*--*--* |
You can work around this problem by installing Xvfb, the X window
virtual frame buffer. I had to install it on the ImageJ server to get the example servlet at http://rsb.info.nih.gov:8080/index.html to work. -wayne On Oct 4, 2006, at 12:26 PM, Kurt De Vos wrote: > I get the same behavior: > > Exception in thread "main" java.awt.HeadlessException: > No X11 DISPLAY variable was set, but this program performed an > operation which requires it. > at java.awt.GraphicsEnvironment.checkHeadless(Unknown Source) > at java.awt.MenuComponent.<init>(Unknown Source) > at java.awt.MenuItem.<init>(Unknown Source) > at java.awt.MenuItem.<init>(Unknown Source) > at java.awt.Menu.<init>(Unknown Source) > at java.awt.Menu.<init>(Unknown Source) > at ij.Menus.addMenuBar(Menus.java:87) > at ij.IJ.init(IJ.java:333) > at ij.IJ.runMacroFile(IJ.java:93) > at ij.ImageJ.main(ImageJ.java:471) > With this error info, it should be possibel to customize ij to run gui > free. > > kurt > > On 4 Oct 2006, at 16:46, Albert Cardona wrote: > >> -Djava.awt.headless=true > > *--*--*--*--*--*--*--*--*--*--*--*--*--* > University of Sheffield > Academic Neurology Unit > Division of Genomic Medicine > E Floor, Medical School > Beech Hill Road > Sheffield > S10 2RX > United Kingdom > > Tel: ++44 (0) 114 271 2473 > Fax: ++44 (0) 114 226 1201 > Email: [hidden email] > *--*--*--*--*--*--*--*--*--*--*--*--*--* > |
In reply to this post by Albert Cardona
Hi,
On Wed, 4 Oct 2006, Albert Cardona wrote: > $ java -classpath ij.jar ij.ImageJ macros/any.txt Did you forget "-batch"? I found a trick which makes it work here: set DISPLAY to empty: $ DISPLAY= java -classpath ij.jar ij.ImageJ -batch macros/any.txt Having said that, I think it is a bug to try to initialize X11 headlessly. Ciao, Dscho |
Hi Dscho,
No, I only forgot "-batch" when writing the email to the list (since I can't copy, or not easily, from the tty). > I found a trick which makes it work here: set DISPLAY to empty: > > $ DISPLAY= java -classpath ij.jar ij.ImageJ -batch macros/any.txt I have tried this, and nothing prints in a tty. Perhaps the job is done but lost, I would have to setup a different kind of macro for that (a macro that does I/O of some sort). > > Having said that, I think it is a bug to try to initialize X11 headlessly. I don't quite understand what you mean. The java is buggy and shouldn't init awt and swing peers when headless? Albert |
Hi,
On Wed, 4 Oct 2006, Albert Cardona wrote: > > I found a trick which makes it work here: set DISPLAY to empty: > > > > $ DISPLAY= java -classpath ij.jar ij.ImageJ -batch macros/any.txt > > > I have tried this, and nothing prints in a tty. I am running Linux, so I have a couple of text consoles. If I run your macro there, with "DISPLAY=", it prints "Hello" and the numbers from 0 to 9. > > Having said that, I think it is a bug to try to initialize X11 headlessly. > > I don't quite understand what you mean. The java is buggy and shouldn't > init awt and swing peers when headless? Java should init AWT (and possibly Swing, even if it is not used in ImageJ), but it should not try to access the contents of the environment variable DISPLAY, if it is not set. The latter is the Java bug I meant. Ciao, Dscho |
Free forum by Nabble | Edit this page |