Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does the ScriptEditor uses the proper javac? #119

Closed
StephanJanosch opened this issue Apr 13, 2015 · 12 comments
Closed

Does the ScriptEditor uses the proper javac? #119

StephanJanosch opened this issue Apr 13, 2015 · 12 comments

Comments

@StephanJanosch
Copy link

I open fiji like this:

open -a "Fiji.app" --args --java-home '/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/'

I need Java 8, because I have an external lib build with Java 8.

Now I am creating a plugin and want to compile it and get errors

Started <hidden>_PlugIn.java at Mon Apr 13 16:19:04 CEST 2015
Compiling 1 file in /var/folders/f6/6jkf220j46nb7vyv12x59g3m0000gp/T/java337162944644509912
/var/folders/f6/6jkf220j46nb7vyv12x59g3m0000gp/T/java337162944644509912/src/main/java/<hidden>_PlugIn.java:4: cannot access <hidden>
bad class file: ZipFileIndexFileObject[/<hidden>)]
class file has wrong version 52.0, should be 50.0
Please remove or make sure it appears in the correct subdirectory of the class path.

Now I wonder, if the script editor uses the javac specified in Fiji call.

I know, that my stuff works, because I can compile it outside Fiji and copy the class file over. It looks like that the built-in javac is called, as this poor guy is still Java6 and cannot read jars made by Java8(class file version 52).

Any thoughts?
And Thanks!

@ctrueden
Copy link
Member

The script editor calls javac from the tools.jar that ships from the ImageJ update site. This is not an ideal situation; see imagej/ImageJ#105 for details. Until that issue is fixed, it will not work to compile Java 7 or Java 8 code in the Script Editor, at least not out of the box.

If you wish, you could try removing tools.jar and ensure the version of Java you're using is a JDK, not just a JRE... then let us know if you manage to get it working. It would be awesome to have a FAQ entry on the subject at http://imagej.net/FAQ.

@StephanJanosch
Copy link
Author

Hey Curstis,

i removed tools-1.4.2.jar and this is the result

Started Autopilot_PlugIn.java at Tue Apr 14 07:58:55 CEST 2015
Compiling 1 file in /var/folders/f6/6jkf220j46nb7vyv12x59g3m0000gp/T/java2211656977806892332
/var/folders/f6/6jkf220j46nb7vyv12x59g3m0000gp/T/java2211656977806892332/src/main/java/<hidden>_PlugIn.java:4: cannot access <hidden>
bad class file: ZipFileIndexFileObject[/<hidden>.jar(<hidden>.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.
import <hidden>;
                                                      ^
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:175)
    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:181)
    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:175)
    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:181)
    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)

@ctrueden
Copy link
Member

OK, so maybe my theory is wrong then. I don't know. If you figure it out, definitely let us know, and/or write a FAQ entry. It would benefit an increasing number of people, as more installations migrate to Java 8.

Unfortunately, I don't have time to look into it myself right now. But I will later this year—for a variety of reasons, this is very likely the year that ImageJ2 will switch to Java 8 and Java 3D 1.6...

@ctrueden ctrueden added this to the m1 milestone May 3, 2015
@StephanJanosch
Copy link
Author

Another try on this: I got rid of javac-1.6.0.24-ubuntu-fiji2.jar of my jars folder and tried using the script editor to compile my java plugin with the java8 dependency (another jar build with java8).

Console:

No javac.jar found (looked in /Users/janosch/Applications/Fiji.app/jars)!

Script editor


Started Autopilot_Image2.java at Fri May 08 09:25:08 CEST 2015
Compiling 1 file in /var/folders/f6/6jkf220j46nb7vyv12x59g3m0000gp/T/java5340943230034245440
/var/folders/f6/6jkf220j46nb7vyv12x59g3m0000gp/T/java5340943230034245440/src/main/java/Autopilot_Image2.java:17: cannot access java.lang.Object
bad class file: java/lang/Object.class(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 Autopilot_Image2 implements Command {
       ^
org/scijava/plugin/Parameter.class(org/scijava/plugin:Parameter.class): warning: Cannot find annotation method 'value()' in type 'java.lang.annotation.Retention': bad class file: java/lang/annotation/Retention.class(java/lang/annotation:Retention.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.
org.scijava.minimaven.JavaCompiler$CompileError: Compile error: 4
    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:175)
    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:181)
    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:175)
    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:181)
    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)

@StephanJanosch
Copy link
Author

Another Test:
removing both

  • tools-1.4.2.jar
  • javac-1.6.0.24-ubuntu-fiji2.jar

gave me this

Could not find javac java.lang.ClassNotFoundException: com.sun.tools.javac.Main, falling back to system javac
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home//jre/bin/javac" (-1)

There is no jre folder in java_home anymore. Maybe I can find the culprit somewhere in the sources.

@StephanJanosch
Copy link
Author

Success (on Mac OS 10.9):

-copy my Java8 based dependency to Fiji.app/plugins
-remove tools-1.4.2.jar and javac-1.6.0.24-ubuntu-fiji2.jar
-export path: export PATH=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin:$PATH
-open Fiji: open -a "Fiji.app" --args --java-home /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/'

Started Autopilot_Image2.java at Fri May 08 13:38:54 CEST 2015
Compiling 1 file in /var/folders/f6/6jkf220j46nb7vyv12x59g3m0000gp/T/java323033200506883184
java.lang.ClassNotFoundException: com.sun.tools.javac.Main
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.scijava.minimaven.JavaCompiler.call(JavaCompiler.java:65)
    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:175)
    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:181)
    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)
Could not find javac java.lang.ClassNotFoundException: com.sun.tools.javac.Main, falling back to system javac
warning: Supported source version 'RELEASE_6' from annotation processor 'org.scijava.annotations.AnnotationProcessor' less than -source '1.8'
1 warning

Although it looks like a failure. ImageJ picks up the javac from the $PATH, compiles the stuff and runs my plugin.

Even the export as .jar works fine.

@ctrueden and @hinerm: It's up to you, to close this issue. I would leave it open, because for an average user this approach seems not very elegant.

@ctrueden
Copy link
Member

ctrueden commented May 8, 2015

Thanks for all the information, @StephanJanosch! We should definitely leave this issue open, since we want the compilation to work "out of the box" with whatever version of Java is being used to run ImageJ itself. And there should never be a need to set or alter any environment variables. We do have plans to make this work—it is just a matter of time.

@ctrueden
Copy link
Member

@StephanJanosch No rush, but when you get a chance, can you please test with the latest Fiji, with the Java-8 update site enabled? Note that you will need to be using Java 8 before enabling this update site, for your installation to continue working. See this news post for some details.

We may also still need to mark the javac component as obsolete on the Java-8 update site. (IIRC we didn't yet.)

@chalkie666
Copy link
Contributor

I get the same error message about Object, got version 52, wants version 50, here is how:
Fiji downloaded, windows 7 64 bit, with java 1.6 bundled. Ran a macro that calls a plugin in the plugins directory which is a .java file - , it gets compiles, and runs fine....this works.
Then rename the Fiji.app/java folder to something else, so Fiji then pick up the system installed java 1.8. Run the same macro that calls the same plugin .java file, but it wont run and throws the error.

so if its using the java compiler of java version 1.6 from tools.jar and but running java 1.8, of course it cant works. This is nasty for a user running plugins from .java source code when they switch to java 1.8.

The easy work around is to use precompiled .class files put in the plugins directory. That just works... so long as there is a .class file to download for the plugin.... lucky for me there was.

@ctrueden
Copy link
Member

@chalkie666 Compiling Java code in the Script Editor will only work with Java 8 if:

  • You enable the Java-8 update site; and
  • You delete jars/javac-1.6.0.24-ubuntu-fiji2.jar and jars/tools-1.4.2.jar

I want to mark those files obsolete on the Java-8 update site, but due to a bug in the Updater, cannot currently do so.

@ctrueden
Copy link
Member

ctrueden commented Jul 20, 2016

I am going to go ahead and remove those files from the core ImageJ and Fiji update sites. That way, with the Java-8 site enabled, Java coding will work in the Script Editor out of the box—meaning that Java coding will work with fresh downloads of Fiji again. People who have not upgraded beyond Java 6 will lose the ability to compile Java code in the Script Editor. But I see no way around that, without extending the Updater to support obsoleting a file in a downstream update site (it currently has no support for this).

@ctrueden
Copy link
Member

I removed those two files. Actually, Java compilation now works in Fiji even without the Java-8 update site enabled, as long as the installation is using Java 8. (I did not test with Java 6, but I am guessing it probably does not work.)

As a side effect, we are now closer to a legal software distribution—it was not kosher to be distributing the tools.jar, but we now no longer do it, so hooray! 🎊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants