How can I run ImgLib2_Plugin.java tutorial code?

Most likely a question that can easily be answered, but also a problem people might stumble across a lot.

In Fiji I opened the Script Editor, then opened the template code ‘ImgLib2_Plugin.java’. I expected that I can now simply hit ‘Run’ and see it working. This turned out to be not the case (see error output below).

Then I thought I might have to save the file in a specific place or make a jar our of it or such. Unfortunately there is no comment in the template code that would show me what I am missing. I would be happy to contribute such a comment if somebody first helps me to understand what I have to do in order to run this plugin.

Thanks,
Florian

Error output in script editor console upon hitting ‘Run’:

java.io.FileNotFoundException: file:/var/folders/f2/w65yzfb925zd084ndn5ynv_00000gr/T/java5098524930706167087/pom.xml (No such file or directory)
	at java.io.FileOutputStream.open(Native Method)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:110)
	at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:235)
	at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:278)
	at org.scijava.plugins.scripting.java.JavaEngine.fakePOM(JavaEngine.java:744)
	at org.scijava.plugins.scripting.java.JavaEngine.writeTemporaryProject(JavaEngine.java:631)
	at org.scijava.plugins.scripting.java.JavaEngine.getMavenProject(JavaEngine.java:532)
	at org.scijava.plugins.scripting.java.JavaEngine.access$600(JavaEngine.java:95)
	at org.scijava.plugins.scripting.java.JavaEngine$Builder.<init>(JavaEngine.java:410)
	at org.scijava.plugins.scripting.java.JavaEngine$Builder.<init>(JavaEngine.java:372)
	at org.scijava.plugins.scripting.java.JavaEngine.compile(JavaEngine.java:198)
	at org.scijava.plugins.scripting.java.JavaEngine.eval(JavaEngine.java:135)
	at org.scijava.plugins.scripting.java.JavaEngine.eval(JavaEngine.java:173)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:174)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
	at org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
java.lang.NullPointerException
	at java.lang.Class.isAssignableFrom(Native Method)
	at org.scijava.plugins.scripting.java.CommandJavaRunner.supports(CommandJavaRunner.java:71)
	at org.scijava.plugins.scripting.java.CommandJavaRunner.supports(CommandJavaRunner.java:46)
	at org.scijava.plugins.scripting.java.DefaultJavaService.run(DefaultJavaService.java:60)
	at org.scijava.plugins.scripting.java.JavaEngine.eval(JavaEngine.java:136)
	at org.scijava.plugins.scripting.java.JavaEngine.eval(JavaEngine.java:173)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:174)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
	at org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

Hi @fjug, I tried the same and for me it worked perfectly.
what I did:

  1. opend the template and saved it (in my case to the desktop)
  2. opend the blobs.png image
  3. pressed the run button

no error message. That’s the output image.

I tried that with two Fiji versions. The last Life-line one and the up-to-date one (just updated) and there was no problem in none of them. I’m currently still running them with the Windows 64-bit version of jdk1.6.0_24.

So, might be a system specific problem (???).

Hi @biovoxxel,
thanks for trying that out. I’m sitting on a Mac, running the latest version of Fiji under Java 1.7.0_71.
Later I will try Java 1.8 instead and maybe also a clean fiji install… once I did that I will post my experience here…

So, I tried to use Java 1.8.0_60 and it was throwing the following exception. Which I unfortunately cannot really interpret why this happens but it seems to be linked to the different Java versions.

   C:\Users\BIOVOX~1\AppData\Local\Temp\java7258394384194572878\src\main\java\ImgLib2_Plugin.java:20: cannot access java.lang.Object
    bad class file: ZipFileIndexFileObject[D:\Fiji\FIJI~3.APP\java\win64\jdk1.8.0_60\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]
    class file has wrong version 52.0, should be 50.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    public class ImgLib2_Plugin<T extends RealType<T> & NativeType<T>> implements PlugInFilter {
           ^
    org.scijava.minimaven.JavaCompiler$CompileError: Compile error: 1
    	at org.scijava.minimaven.JavaCompiler.call(JavaCompiler.java:80)
    	at org.scijava.minimaven.MavenProject.build(MavenProject.java:477)
    	at org.scijava.minimaven.MavenProject.build(MavenProject.java:406)
    	at org.scijava.minimaven.MavenProject.build(MavenProject.java:391)
    	at org.scijava.plugins.scripting.java.JavaEngine.compile(JavaEngine.java:211)
    	at org.scijava.plugins.scripting.java.JavaEngine.eval(JavaEngine.java:135)
    	at org.scijava.plugins.scripting.java.JavaEngine.eval(JavaEngine.java:173)
    	at org.scijava.script.ScriptModule.run(ScriptModule.java:174)
    	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
    	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
    	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
    	at org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    	at java.lang.Thread.run(Thread.java:745)
    java.lang.NullPointerException
    	at java.lang.Class.isAssignableFrom(Native Method)
    	at org.scijava.plugins.scripting.java.CommandJavaRunner.supports(CommandJavaRunner.java:71)
    	at org.scijava.plugins.scripting.java.CommandJavaRunner.supports(CommandJavaRunner.java:46)
    	at org.scijava.plugins.scripting.java.DefaultJavaService.run(DefaultJavaService.java:60)
    	at org.scijava.plugins.scripting.java.JavaEngine.eval(JavaEngine.java:136)
    	at org.scijava.plugins.scripting.java.JavaEngine.eval(JavaEngine.java:173)
    	at org.scijava.script.ScriptModule.run(ScriptModule.java:174)
    	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
    	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
    	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
    	at org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    	at java.lang.Thread.run(Thread.java:745)

That means it found a Java 8 version of Object and it wants a Java 6 version. The 52, 51, 50, etc… are major versions numbers and I do not know why they can’t just translate them to “6, 7, 8”. See this table for more info.

@biovoxxel’s problem may be different than @fjug’s… it looks like the Java script language tries to make a temporary pom, presumably so it can use Maven to do the compilation. For @fjug the pom wasn’t found, for @biovoxxel maybe there may was something left over from when you ran with J6…?

I think there’s some doucmentation about how Java sucks in the script editor. @ctrueden may know where it is. But I think the message here is that compiled languages are the worst for “scripting” and we should use interpreted languages for most templates, tutorials and examples - especially those user-facing.

1 Like

Not documentation, but open issues:

Hi, I am having the same trouble with the “class file has wrong version 52.0, should be 50.0”. I am not sure if I understood correctly, the idea is that the problem is the java version so to fix it I should try to install a different java version? or better follow this instructions http://imagej.net/2015-12-22_-_The_road_to_Java_8 and try to adapt my imageJ?
I checked and I do have Java version 8

thanks

Are you building Java plugins in the script editor? You may actually need to run ImageJ with Java 6 if you’re getting that error.

See also checking the Java version and running with alternate versions

Delete the files jars/javac-1.6.0.24-ubuntu-fiji2.jar and jars/tools-1.4.2.jar. Then the Script Editor should use Java 8 to compile and run Java code, as desired.

(I would flag these files as obsolete on the Java-8 update site, but a bug in the updater currently prevents me from doing that.)

2 Likes

Hi, thanks for the replies. I deleted the files and it seems to be working now. Although I get this warnings:

Compiling 1 file in C:\Users\juanpps\AppData\Local\Temp\java1558948365660346940
No javac.jar found (looked in K:\DOCUME~1\Fiji_app\jars)!
warning: K:\DOCUME~1\Fiji_app\java\win64\jdk1.8.0_66\jre\lib\rt.jar(java\lang\Object.class): major version 52 is newer than 51, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
warning: K:\DOCUME~1\Fiji_app\java\win64\jdk1.8.0_66\jre\lib\rt.jar(java\lang\String.class): major version 52 is newer than 51, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
warning: K:\DOCUME~1\Fiji_app\java\win64\jdk1.8.0_66\jre\lib\rt.jar(java\lang\Object.class): major version 52 is newer than 51, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
warning: K:\DOCUME~1\Fiji_app\java\win64\jdk1.8.0_66\jre\lib\rt.jar(java\lang\String.class): major version 52 is newer than 51, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
2 warnings

should I just ignore them or do something about it?

best

Weird—that error makes it sound like a Java 7 compiler is somehow being used, even though you launched ImageJ with Java 8?

If all works, I would suggest ignoring for now. We will continue to iron out issues relating to Java 8 over the course of this year.

Well I did not specified with which java to launch imagej, I just checked that the version that appears installed is the version 8, maybe version 7 is also there and it is using that one. Thanks for your help.

best
Juan

Sounds plausible; you can verify by following these directions.

1 Like