[ImageJ-devel] jython scripting, No compatible service: io.scif.SCIFIOService

Mark Hiner hinerm at gmail.com
Tue Feb 25 11:42:34 CST 2014


Hi Harri,

 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!

 Anyway, when running from the command line:

CP=`find /home/hajaalin/Software/fiji-20140219/Fiji.app/jars -name '*.jar'
> |sed ':a;N;$!ba;s/\n/:/g'`
>

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).

 I used this stack
overflow<http://stackoverflow.com/questions/4729863/using-bash-how-do-you-make-a-classpath-out-of-all-files-in-a-directory>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 this SO
post<http://stackoverflow.com/questions/537682/how-can-i-add-jars-to-the-classpath-when-i-invoke-jython-without-adding-them-t>,
there is a convenient jython flag for passing the java classpath directly
(without having to set environment variables).

 My end result was the following command:

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

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: )

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.

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.

Thanks again for working on scripts like this. Let us know if you run into
any more problems.

- Mark


On Mon, Feb 24, 2014 at 4:34 AM, Harri Jäälinoja <
harri.jaalinoja at helsinki.fi> wrote:

> Hi again,
>
> here's my second try: I made a pom.xml (attached) and retrieved dependency
> jar files with:
>
> mvn dependency:copy-dependencies
>
>
> But I still get the same error as before:
>
> CP=`find /home/hajaalin/Software/mvn-IJ2/target/dependency -name '*.jar'
> |sed ':a;N;$!ba;s/\n/:/g'`
> jython -Dpython.path=$CP /home/hajaalin/Software/fiji-
> 20140219/Fiji.app/macros/imglib0.py /home/hajaalin/Data/Misha/
> composite1.ome.tif
>
> [WARNING] Class pool is empty: forgot to call Thread#setClassLoader?
> Traceback (most recent call last):
>   File "/home/hajaalin/Software/fiji-20140219/Fiji.app/macros/imglib0.py",
> line 16, in <module>
>
>     io = ImgOpener()
>     at org.scijava.service.ServiceHelper.loadService(
> ServiceHelper.java:218)
> ...
>
> java.lang.IllegalArgumentException: java.lang.IllegalArgumentException:
> No compatible service: io.scif.SCIFIOService
>
>
> 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?
>
> Thanks,
> Harri
>
>
>
> On 21/02/14 13:25, Harri Jäälinoja wrote:
>
>> Hi,
>>
>> 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.
>>
>> mkdir fiji-20140219
>> cd fiji-20140219/
>> wget http://jenkins.imagej.net/job/Stable-Fiji/
>> lastSuccessfulBuild/artifact/fiji-linux64.tar.gz
>> tar xf fiji-linux64.tar.gz
>>
>>
>> Then I just put all the jar files in the Fiji distribution in one long
>> variable and gave that as the classpath for Jython
>> CP=`find /home/hajaalin/Software/fiji-20140219/Fiji.app/jars -name
>> '*.jar' |sed ':a;N;$!ba;s/\n/:/g'`
>>
>> Here's my test script:
>>
>> ----- imglib0.py ------
>> import sys
>>
>> #from io.scif.config import SCIFIOConfig
>> from io.scif.config import *
>> from io.scif.img import ImgIOException,ImgOpener
>>
>> from java.io import File
>>
>> from net.imglib2.img import Img
>> from net.imglib2.img.display.imagej import ImageJFunctions
>> from net.imglib2.type import NativeType
>> from net.imglib2.type.numeric import RealType
>>
>> filename = sys.argv[1]
>>
>> io = ImgOpener()
>> config = SCIFIOConfig()
>> config.imgOpenerSetImgModes( SCIFIOConfig.ImgMode.CELL )
>> img = io.openImg(filename)
>>
>> ImageJFunctions.show( img )
>> ---------------------------
>>
>>
>> When I run it, I get an error I've seen on the list before:
>>
>> hajaalin at biotek973:~/Software/fiji-20140219/Fiji.app$ jython
>> -Dpython.path=$CP macros/imglib0.py /home/hajaalin/Data/Misha/
>> composite1.ome.tif
>> [WARNING] Class pool is empty: forgot to call Thread#setClassLoader?
>> Traceback (most recent call last):
>>   File "macros/imglib0.py", line 16, in <module>
>>     io = ImgOpener()
>>     at org.scijava.service.ServiceHelper.loadService(
>> ServiceHelper.java:218)
>>     at org.scijava.service.ServiceHelper.loadService(
>> ServiceHelper.java:172)
>>     at org.scijava.service.ServiceHelper.loadServices(
>> ServiceHelper.java:149)
>>     at org.scijava.Context.<init>(Context.java:179)
>>     at org.scijava.Context.<init>(Context.java:121)
>>     at org.scijava.Context.<init>(Context.java:109)
>>     at io.scif.img.AbstractImgIOComponent.<init>(
>> AbstractImgIOComponent.java:59)
>>     at io.scif.img.ImgOpener.<init>(ImgOpener.java:94)
>>     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
>> Method)
>>     at sun.reflect.NativeConstructorAccessorImpl.newInstance(
>> NativeConstructorAccessorImpl.java:57)
>>     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
>> DelegatingConstructorAccessorImpl.java:45)
>>     at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
>>     at org.python.core.PyReflectedConstructor.constructProxy(
>> PyReflectedConstructor.java:163)
>>
>> java.lang.IllegalArgumentException: java.lang.IllegalArgumentException:
>> No compatible service: io.scif.SCIFIOService
>>
>>
>> If I try to run the script via Fiji, I don't get even that far:
>>
>> hajaalin at biotek973:~/Software/fiji-20140219/Fiji.app$ ./ImageJ-linux64
>> macros/imglib0.py /home/hajaalin/Data/Misha/composite1.ome.tif
>> Traceback (most recent call last):
>>   File "macros/imglib0.py", line 4, in <module>
>>     from io.scif.config import *
>> ImportError: No module named io
>>
>>
>> So now my questions are:
>> 1. Is there a better way to get all the dependency jars?
>> 2. Is there something wrong with my general setup (jython + script +
>> required jars)?
>>
>>
>> Thanks, best regards,
>> Harri
>>
>>
>
> --
> __________________________________________________
> Harri Jäälinoja
> Light Microscopy Unit
> Institute of Biotechnology, University of Helsinki
> http://www.biocenter.helsinki.fi/bi/lmu/
> +358 9 191 59370 fax +358 9 191 59366
>
>
> _______________________________________________
> ImageJ-devel mailing list
> ImageJ-devel at imagej.net
> http://imagej.net/mailman/listinfo/imagej-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://imagej.net/pipermail/imagej-devel/attachments/20140225/de09ebc5/attachment.html>


More information about the ImageJ-devel mailing list