<div dir="ltr"><div><div><div><div>Hi Harri,<br><br></div> First of all, I think it's awesome that you're doing this. It's great to see someone testing things from the scripting side, and it's definitely revealing some weaknesses. So thank you for that!<br>

<br></div> Anyway, when running from the command line:<br><br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">CP=`find /home/hajaalin/Software/fiji-20140219/Fiji.app/jars -name '*.jar' |sed ':a;N;$!ba;s/\n/:/g'`<br>

</blockquote><br></div>You have the right idea here, but your find command prints each jar on its own line. For use in a Java classpath, you need a single line with each jar separated by the path separator appropriate for your system (';' for Windows, ':' for Linux/OSX).<br>

<br></div> I used <a href="http://stackoverflow.com/questions/4729863/using-bash-how-do-you-make-a-classpath-out-of-all-files-in-a-directory">this stack overflow</a> question to find a good way to format the jar list for the classpath. Note that they talk about Java 6 supporting jars/* notation, but I couldn't get that to work with jython. Also, according to <a href="http://stackoverflow.com/questions/537682/how-can-i-add-jars-to-the-classpath-when-i-invoke-jython-without-adding-them-t">this SO post</a>, there is a convenient jython flag for passing the java classpath directly (without having to set environment variables).<br>

<div><div><div><div><div><br></div><div> My end result was the following command:<br><br>jython -J-cp "$(find find /home/hajaalin/Software/fiji-20140219/Fiji.app/jars -print0 -name '*.jar' | tr '\0' ':')blub" macros/imglib0.py /home/hajaalin/Data/Misha/composite1.ome.tif<br>

<br></div><div>Note the "blub" at the end is meaningless, but the tr call has a terminating ':' character which we probably shouldn't leave open on the classpath. (e.g. JAR:JAR:JAR:JAR:blub is preferable to JAR:JAR:JAR:JAR: )<br>

<br></div><div>So, this ran for me and mostly worked! However, even though the image opened I did get some errors along the way, I believe related to the error you saw when trying to run your script from Fiji - SCIFIO 0.9.2 has some breaking API changes in it, and it looks like some downstream jars weren't updated as part of Fiji.<br>

<br></div><div>If you run this using the pom.xml dependency trick that you came up with in your second e-mail, I didn't get any exceptions when running from the command line. But I will work on getting the Fiji dependencies straightened out so that you can use them, or run using Fiji directly.<br>

<br></div><div>Thanks again for working on scripts like this. Let us know if you run into any more problems.<br><br></div><div>- Mark<br></div></div></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">

On Mon, Feb 24, 2014 at 4:34 AM, Harri Jäälinoja <span dir="ltr"><<a href="mailto:harri.jaalinoja@helsinki.fi" target="_blank">harri.jaalinoja@helsinki.fi</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi again,<br>
<br>
here's my second try: I made a pom.xml (attached) and retrieved dependency jar files with:<br>
<br>
mvn dependency:copy-dependencies<br>
<br>
<br>
But I still get the same error as before:<br>
<br>
CP=`find /home/hajaalin/Software/mvn-<u></u>IJ2/target/dependency -name '*.jar' |sed ':a;N;$!ba;s/\n/:/g'`<br>
jython -Dpython.path=$CP /home/hajaalin/Software/fiji-<u></u>20140219/Fiji.app/macros/<u></u>imglib0.py /home/hajaalin/Data/Misha/<u></u>composite1.ome.tif<div class=""><br>
[WARNING] Class pool is empty: forgot to call Thread#setClassLoader?<br>
Traceback (most recent call last):<br></div>
  File "/home/hajaalin/Software/fiji-<u></u>20140219/Fiji.app/macros/<u></u>imglib0.py", line 16, in <module><div class=""><br>
    io = ImgOpener()<br>
    at org.scijava.service.<u></u>ServiceHelper.loadService(<u></u>ServiceHelper.java:218)<br></div>
...<div class=""><br>
java.lang.<u></u>IllegalArgumentException: java.lang.<u></u>IllegalArgumentException: No compatible service: io.scif.SCIFIOService<br>
<br>
<br></div>
Now it's maybe only a matter of getting the versions for pom-scijava and ij-app right. How can I find out which version to use?<br>
<br>
Thanks,<br>
Harri<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
On 21/02/14 13:25, Harri Jäälinoja wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I started to learn about ImgLib2 for the purpose of creating scripts I can run headlessly. I would like to use jython since I already used that with ImageJ1. First I downloaded a recent Fiji version. My idea was that this would be the easiest way to get the dependencies (scifio, imglib2 etc.) right.<br>


<br>
mkdir fiji-20140219<br>
cd fiji-20140219/<br>
wget <a href="http://jenkins.imagej.net/job/Stable-Fiji/lastSuccessfulBuild/artifact/fiji-linux64.tar.gz" target="_blank">http://jenkins.imagej.net/job/<u></u>Stable-Fiji/<u></u>lastSuccessfulBuild/artifact/<u></u>fiji-linux64.tar.gz</a><br>


tar xf fiji-linux64.tar.gz<br>
<br>
<br>
Then I just put all the jar files in the Fiji distribution in one long variable and gave that as the classpath for Jython<br>
CP=`find /home/hajaalin/Software/fiji-<u></u>20140219/Fiji.app/jars -name '*.jar' |sed ':a;N;$!ba;s/\n/:/g'`<br>
<br>
Here's my test script:<br>
<br>
----- imglib0.py ------<br>
import sys<br>
<br>
#from io.scif.config import SCIFIOConfig<br>
from io.scif.config import *<br>
from io.scif.img import ImgIOException,ImgOpener<br>
<br>
from <a href="http://java.io" target="_blank">java.io</a> import File<br>
<br>
from net.imglib2.img import Img<br>
from net.imglib2.img.display.imagej import ImageJFunctions<br>
from net.imglib2.type import NativeType<br>
from net.imglib2.type.numeric import RealType<br>
<br>
filename = sys.argv[1]<br>
<br>
io = ImgOpener()<br>
config = SCIFIOConfig()<br>
config.imgOpenerSetImgModes( SCIFIOConfig.ImgMode.CELL )<br>
img = io.openImg(filename)<br>
<br>
ImageJFunctions.show( img )<br>
---------------------------<br>
<br>
<br>
When I run it, I get an error I've seen on the list before:<br>
<br>
hajaalin@biotek973:~/Software/<u></u>fiji-20140219/Fiji.app$ jython -Dpython.path=$CP macros/imglib0.py /home/hajaalin/Data/Misha/<u></u>composite1.ome.tif<br>
[WARNING] Class pool is empty: forgot to call Thread#setClassLoader?<br>
Traceback (most recent call last):<br>
  File "macros/imglib0.py", line 16, in <module><br>
    io = ImgOpener()<br>
    at org.scijava.service.<u></u>ServiceHelper.loadService(<u></u>ServiceHelper.java:218)<br>
    at org.scijava.service.<u></u>ServiceHelper.loadService(<u></u>ServiceHelper.java:172)<br>
    at org.scijava.service.<u></u>ServiceHelper.loadServices(<u></u>ServiceHelper.java:149)<br>
    at org.scijava.Context.<init>(<u></u>Context.java:179)<br>
    at org.scijava.Context.<init>(<u></u>Context.java:121)<br>
    at org.scijava.Context.<init>(<u></u>Context.java:109)<br>
    at io.scif.img.<u></u>AbstractImgIOComponent.<init>(<u></u>AbstractImgIOComponent.java:<u></u>59)<br>
    at io.scif.img.ImgOpener.<init>(<u></u>ImgOpener.java:94)<br>
    at sun.reflect.<u></u>NativeConstructorAccessorImpl.<u></u>newInstance0(Native Method)<br>
    at sun.reflect.<u></u>NativeConstructorAccessorImpl.<u></u>newInstance(<u></u>NativeConstructorAccessorImpl.<u></u>java:57)<br>
    at sun.reflect.<u></u>DelegatingConstructorAccessorI<u></u>mpl.newInstance(<u></u>DelegatingConstructorAccessorI<u></u>mpl.java:45)<br>
    at java.lang.reflect.Constructor.<u></u>newInstance(Constructor.java:<u></u>526)<br>
    at org.python.core.<u></u>PyReflectedConstructor.<u></u>constructProxy(<u></u>PyReflectedConstructor.java:<u></u>163)<br>
<br>
java.lang.<u></u>IllegalArgumentException: java.lang.<u></u>IllegalArgumentException: No compatible service: io.scif.SCIFIOService<br>
<br>
<br>
If I try to run the script via Fiji, I don't get even that far:<br>
<br>
hajaalin@biotek973:~/Software/<u></u>fiji-20140219/Fiji.app$ ./ImageJ-linux64 macros/imglib0.py /home/hajaalin/Data/Misha/<u></u>composite1.ome.tif<br>
Traceback (most recent call last):<br>
  File "macros/imglib0.py", line 4, in <module><br>
    from io.scif.config import *<br>
ImportError: No module named io<br>
<br>
<br>
So now my questions are:<br>
1. Is there a better way to get all the dependency jars?<br>
2. Is there something wrong with my general setup (jython + script + required jars)?<br>
<br>
<br>
Thanks, best regards,<br>
Harri<br>
<br>
</blockquote>
<br>
<br>
-- <br>
______________________________<u></u>____________________<br>
Harri Jäälinoja<br>
Light Microscopy Unit<br>
Institute of Biotechnology, University of Helsinki<br>
<a href="http://www.biocenter.helsinki.fi/bi/lmu/" target="_blank">http://www.biocenter.helsinki.<u></u>fi/bi/lmu/</a><br>
<a href="tel:%2B358%209%20191%2059370" value="+358919159370" target="_blank">+358 9 191 59370</a> fax <a href="tel:%2B358%209%20191%2059366" value="+358919159366" target="_blank">+358 9 191 59366</a><br>
<br>
</div></div><br>_______________________________________________<br>
ImageJ-devel mailing list<br>
<a href="mailto:ImageJ-devel@imagej.net">ImageJ-devel@imagej.net</a><br>
<a href="http://imagej.net/mailman/listinfo/imagej-devel" target="_blank">http://imagej.net/mailman/listinfo/imagej-devel</a><br>
<br></blockquote></div><br></div>