[ImageJ-devel] [fiji-devel] creating io.scif.img.ImgOpener currently fails in Fiji

Curtis Rueden ctrueden at wisc.edu
Fri Aug 22 09:41:22 CDT 2014


Hi Tobias,

> java.lang.IllegalArgumentException: Invalid service:
net.imagej.legacy.LegacyAppEventService
>         at
org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:280)
...
>         at org.scijava.Context.<init>(Context.java:128)
>         at
io.scif.img.AbstractImgIOComponent.<init>(AbstractImgIOComponent.java:57)
>         at io.scif.img.ImgOpener.<init>(ImgOpener.java:94)

Actually, this problem is a known bug, for which I am already working on a
fix:

    https://github.com/imagej/imagej-legacy/pull/88

It is not a problem in your code, Tobias.

Basically, the problem comes down to this "AppEventService" and how the
design of it works. I have a strategy in mind for a new design that avoids
the "cascade" of service dependencies which end up pulling in a
LegacyService into a pure SCIFIO context, which is what causes this error.

Feel free to comment on the PR if you wish to follow the progress.

Regards,
Curtis


On Fri, Aug 22, 2014 at 9:35 AM, Tobias Pietzsch <pietzsch at mpi-cbg.de>
wrote:

> Hi Johannes,
>
> On 22 Aug 2014, at 09:04, Johannes Schindelin <Johannes.Schindelin at gmx.de>
> wrote:
>
> Hi Tobias,
>
> On Fri, 22 Aug 2014, Tobias Pietzsch wrote:
>
> Currently
> new io.scif.img.ImgOpener();
> fails with
> java.lang.IllegalArgumentException: Invalid service:
> net.imagej.legacy.LegacyAppEventService
>
>
> Yep, the explanation is very easy:
>
> [...]
> Caused by: java.lang.UnsupportedOperationException: Cannot instantiate
> more than one DefaultLegacyService
> […]
>
>
> I missed that...
>
>
> There is already a context, including a legacy service. Unfortunately, the
> best way to get at this context from an *ImageJ 1.x plugin* that I could
> come up with is:
>
> import org.scijava.Context;
>
> ...
>
> final Context context = (Context)
>  IJ.runPlugIn(Context.class.getName(), "");
> final ImgOpener opener = new ImgOpener(context);
>
> (There is no way to make that more convenient without letting SCIFIO
> depend on ImageJ 1.x, which is of course a big no-no).
>
>
> The problem with this solution you suggested is that it does not work in
> Eclipse:
> Exception in thread "main" java.lang.IllegalArgumentException: Invalid
> service: net.imagej.legacy.DefaultLegacyService
>
> As much as I understand the need for the runtime service discovery used by
> the scijava stack, there are certainly downsides to it.
> My feeling is that in some ways it undermines the advantages that we have
> gained by switching to maven.
> I can import a maven project into my Eclipse, and all the dependencies are
> there, explicitly and automatically, which is really very convenient.
> Except now all dependencies are not there anymore because now there are
> non-obvious (to me) implicit runtime dependencies.
> I find this unfortunate.
>
> That being said, I found a solution that works for now, both in Eclipse
> and in Fiji
>     final ImgOpener opener = new ImgOpener( new Context(
> SCIFIOService.class, AppService.class, StatusService.class ) );
> This avoids requiring the net.imagej.legacy.LegacyAppEventService.
> It seems to work, but I’m not sure: Are there any downsides to that?
>
> best regards,
> Tobias
>
>
> Of course, you could also turn your plugin into an ImageJ2 plugin -- which
> is handled properly in Fiji thanks to Fiji Just Being ImageJ2 -- and then
> it would become as easy as:
>
>  @Parameter
>  private IOService io;
>
>  ...
>   // use the IOService (which lets SCIFIO handle
>  // things) to open your dataset
>
> Ciao,
> Johannes
>
> --
> --
> Please avoid top-posting, and please make sure to reply-to-all!
>
> Mailing list web interface: http://groups.google.com/group/fiji-devel
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Fiji-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to fiji-devel+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://imagej.net/pipermail/imagej-devel/attachments/20140822/2782c54a/attachment.html>


More information about the ImageJ-devel mailing list