problems with running macros from the command line
Posted by Albert Cardona on
URL: http://imagej.273.s1.nabble.com/problems-with-running-macros-from-the-command-line-tp3701388.html
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