Make ImageJ/ Fiji Jython script with ij and loci classes work from bash script

165 views Asked by At

So far, I exectuted my jython plugins from the script editor in Fiji. I would like to execute my jython scripts from in the command line.

When executing jython myscript.py at the line

from ij import IJ

I get the error:

ImportError: No module named ij

I guess it means that the jar file of ij can’t be found, as it usually was found by the ImageJ editor.

So I set the java classpath:

java -cp “/home/user/input_bash/jars/ij.jar” ij

Then I am getting the error:

Main class not found. (Fehler: Hauptklasse ij konnte nicht gefunden oder geladen werden) Cause: java.lang.ClassNotFoundException: ij

I am new to java, does that mean I am not working with the right jars?

I also used the editor to execute:

from ij import IJ;

print(IJ.getClassLoader().loadClass("ij.IJ")
    .getResource("IJ.class").toString());

Which gives me the directory: /home/user/Software/Fiji.app/jars/ij-1.53c.jar!/ij/IJ.class

This means the editor uses the class inside ij-1.53c.jar! Then I tried: java -cp "/home/lisa/Software/Fiji.app/jars/ij-1.53c.jar\!/ij" ij

with an additional \ due to the !.

I am still getting the same classNotFoundException.

1

There are 1 answers

0
Curtis On

When I run a jython script at the command line, I use jython.jar like this:

java -jar jython.jar somescript.py

If you have external dependencies in jython modules or jars, you may add them to the classpath so they are picked up. You may also need to add the paths to jython modules to the sys.path:

import sys
sys.path.append("<path to modules>")