imagej / imagej2

Open scientific N-dimensional image processing :microscope: :sparkler:
https://imagej.net/
BSD 2-Clause "Simplified" License
1.2k stars 337 forks source link

Improve behavior with Java 10 #197

Open ctrueden opened 6 years ago

ctrueden commented 6 years ago

ImageJ2 and Fiji work with Java 10 but there are some annoyances that need to be addressed.

paulmenzel commented 6 years ago

Why not create a separate issue for each item?

ctrueden commented 6 years ago

@paulmenzel Feel free if you have time.

ctrueden commented 6 years ago

As of ij-1.52b, I note that the JavaScript dialog box no longer appears, and the NoClassDefFoundError is also resolved. I am guessing @rasband fixed these issues?

cortig commented 6 years ago

I'm in 1.52c and I still see the java.lang.NoClassDefFoundError when I launch the app… The other warnings seem to be gone though.

ctrueden commented 6 years ago

@cortig Yeah, I think I spoke too soon, sorry. I will work on fixing the NoSuchMethodError (from the fiji-compat library) soon... hopefully before end of June.

I do urge you to stick with Java 8 though if possible, until we have time to address the main problems, which are A) reflection issues; and B) updating the ImageJ software stack to declare Java module metadata properly. I do not expect we will migrate beyond Java 8 until at least next year, possibly later.

cortig commented 6 years ago

Thanks for letting me know @ctrueden. That's sad, everything felt snappier with Java 10 (not sure whether it's real or just perceived but that's the impression I had).

ctrueden commented 6 years ago

everything felt snappier with Java 10

Cool, glad to hear. We'll try to get the really obnoxious errors above ironed out, so that you can keep using Java 10 in practice, even if it isn't "recommended" per se for a while.

Speaking of speed, Java 10 includes an experimental new JIT compiler called Graal that is supposed to be even faster after initial warmup time. You can enable it by passing -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -- as part of the ImageJ Launcher command. Apparently Twitter's production infrastructure switched to this new JIT and saved >10% of their CPU expense. Give it a spin if you are feeling bored and adventurous some day. :-)

slokhorst commented 6 years ago

Looks like Java 10 (and 9) support has deteriorated in the latest release: I now get the following error when trying to use it:

[WARNING] Rule 2: org.apache.maven.plugins.enforcer.RequireJavaVersion failed with message:
Detected JDK Version: 10.0.1 is not in the allowed range [1.8.0-101,1.8.9999].
ctrueden commented 6 years ago

@slokhorst That error is a build-time error, added intentionally to prevent people from trying to build with Java 9 or 10 by default. Building with Java 8 is strongly recommended. You can still run the program with Java 9 or 10, subject to the discussion above. You can also build with Java 10 by explicitly writing:

mvn -Dscijava.jvm.build.version=10

But depending on the component, this may or may not work, and is not currently officially supported.

aschain commented 5 years ago

Not sure if this is the place to drop this, but on Windows 10, with Java 11 (but also I think this happened with Java 9 or 10) I get these errors:

Initially I get these two errors:

[ERROR]: Cannot locate JRE jar in C:\PROGRA~1\Java\JDK-11~1.1
[ERROR] Cannot create plugin: class='org.scijava.ui.swing.script.languagesupport.JavaLanguageSupportPlugin', priority=0.0, enabled=true, pluginType=LanguageSupportPlugin
java.lang.IllegalArgumentException: info cannot be null
    at org.fife.rsta.ac.java.JarManager.addClassFileSource(JarManager.java:157)
    at org.fife.rsta.ac.java.JarManager.addCurrentJreClassFileSource(JarManager.java:193)
    at org.scijava.ui.swing.script.languagesupport.JavaLanguageSupportPlugin.<init>(JavaLanguageSupportPlugin.java:56)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at java.base/java.lang.Class.newInstance(Class.java:584)
    at org.scijava.plugin.PluginInfo.createInstance(PluginInfo.java:306)
    at org.scijava.plugin.DefaultPluginService.createInstance(DefaultPluginService.java:237)
    at org.scijava.plugin.DefaultPluginService.createInstances(DefaultPluginService.java:226)
    at org.scijava.plugin.DefaultPluginService.createInstancesOfType(DefaultPluginService.java:217)
    at org.scijava.plugin.AbstractSingletonService.initInstances(AbstractSingletonService.java:138)
    at org.scijava.plugin.AbstractSingletonService.getInstances(AbstractSingletonService.java:77)
    at org.scijava.plugin.SingletonService.lambda$initialize$0(SingletonService.java:97)
    at org.scijava.object.ObjectIndex.resolvePending(ObjectIndex.java:388)
    at org.scijava.object.ObjectIndex.get(ObjectIndex.java:133)
    at org.scijava.object.DefaultObjectService.getObjects(DefaultObjectService.java:87)
    at org.scijava.display.DefaultDisplayService.getDisplays(DefaultDisplayService.java:166)
    at org.scijava.ui.DefaultUIService.showUI(DefaultUIService.java:159)
    at org.scijava.ui.DefaultUIService.showUI(DefaultUIService.java:142)
    at org.scijava.AbstractGateway.launch(AbstractGateway.java:104)
    at net.imagej.Main.main(Main.java:55)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:279)
    at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:186)
    at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:77)

And then, if I try to compile a java plugin with the script editor, I get a ton of minimaven errors like this in the script editor output:

Skipping artifact 
                org.scijava.scripting.java
            :
                TrackMate_-4
            :
                1.0.0
             (for 
        org.scijava.scripting.java
    :
        Image_Test
    :
        1.0.0-SNAPSHOT
    ): not found
Trying to download http://maven.imagej.net/service/local/repo_groups/public/content//
                org/scijava/scripting/java
            /
                TrackMate_-4
            /
                1.0.0
            /
                TrackMate_-4
            -
                1.0.0
            .pom.sha1
Trying to download http://repo1.maven.org/maven2//
                org/scijava/scripting/java
            /
                TrackMate_-4
            /
                1.0.0
            /
                TrackMate_-4
            -
                1.0.0
            .pom.sha1
java.io.FileNotFoundException: Could not download 
                TrackMate_-4
            -
                1.0.0
            .jar
    at org.scijava.minimaven.MavenProject.download(MavenProject.java:198)
    at org.scijava.minimaven.MavenProject.maybeDownloadAutomatically(MavenProject.java:1372)
    at org.scijava.minimaven.MavenProject.findPOM(MavenProject.java:1305)
    at org.scijava.minimaven.MavenProject.getDependencies(MavenProject.java:952)
    at org.scijava.minimaven.MavenProject.getDependencies(MavenProject.java:894)
    at org.scijava.minimaven.MavenProject.checkUpToDate(MavenProject.java:220)
    at org.scijava.minimaven.MavenProject.upToDate(MavenProject.java:206)
    at org.scijava.minimaven.MavenProject.build(MavenProject.java:481)
    at org.scijava.minimaven.MavenProject.build(MavenProject.java:463)
    at org.scijava.minimaven.MavenProject.build(MavenProject.java:446)
    at org.scijava.plugins.scripting.java.JavaEngine.compile(JavaEngine.java:209)
    at org.scijava.plugins.scripting.java.JavaEngine.eval(JavaEngine.java:136)
    at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
    at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
Could not download 

and at the same time the imagej console says this:

java.net.MalformedURLException: Illegal character in URL
    at java.base/sun.net.www.protocol.http.HttpURLConnection.checkURL(HttpURLConnection.java:868)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.<init>(HttpURLConnection.java:875)
    at java.base/sun.net.www.protocol.http.Handler.openConnection(Handler.java:62)
    at java.base/sun.net.www.protocol.http.Handler.openConnection(Handler.java:57)
    at java.base/java.net.URL.openConnection(URL.java:1051)
    at org.scijava.minimaven.BuildEnvironment.download(BuildEnvironment.java:606)
    at org.scijava.minimaven.BuildEnvironment.downloadAndVerify(BuildEnvironment.java:462)
    at org.scijava.minimaven.BuildEnvironment.downloadAndVerify(BuildEnvironment.java:452)
    at org.scijava.minimaven.BuildEnvironment.downloadAndVerify(BuildEnvironment.java:443)
    at org.scijava.minimaven.MavenProject.download(MavenProject.java:190)
    at org.scijava.minimaven.MavenProject.maybeDownloadAutomatically(MavenProject.java:1372)
    at org.scijava.minimaven.MavenProject.findPOM(MavenProject.java:1305)
    at org.scijava.minimaven.MavenProject.getDependencies(MavenProject.java:952)
    at org.scijava.minimaven.MavenProject.getDependencies(MavenProject.java:894)
    at org.scijava.minimaven.MavenProject.checkUpToDate(MavenProject.java:220)
    at org.scijava.minimaven.MavenProject.upToDate(MavenProject.java:211)
    at org.scijava.minimaven.MavenProject.build(MavenProject.java:481)
    at org.scijava.minimaven.MavenProject.build(MavenProject.java:463)
    at org.scijava.minimaven.MavenProject.build(MavenProject.java:446)
    at org.scijava.minimaven.MavenProject.build(MavenProject.java:431)
    at org.scijava.plugins.scripting.java.JavaEngine.compile(JavaEngine.java:297)
    at org.scijava.ui.swing.script.TextEditor$24.run(TextEditor.java:2079)

Also, another nice java 9+ advantage is on high-dpi windows computers, you get the full resolution of the images. Like, if you have a 4k screen and the window DPI scale is set to 2.0, when the image in imagej is displayed at a zoom of 50%, I think it is actually displaying the 100% pixel for pixel image. In java 8 it just doubles the pixels always so at 50% it is a 2x display of the 50% scaled image.

ctrueden commented 5 years ago

Making progressing toward Java 11!

@aschain The info cannot be null error is now fixed with scijava/script-editor@3899427ac930c534911284f7d3cf46d79371fed0. I released script-editor 0.5.3 but it is not yet uploaded to the core update site. The minimaven issues I am not sure (have not reproduced myself); please file a separate issue if they persist.

@cortig The NoSuchMethodError and NoClassDefFoundError should be fixed with fiji/fiji@15f288f4af6a929c7b16ec4373b68be01d8b64f4 although A) no new fiji artifact has been released or uploaded yet; and B) after installing the latest fiji snapshot into your local Fiji you should also delete the jars/fiji-compat.jar since it is obsolete and could create conflicts.

cortig commented 4 years ago

FYI. I tried playing again with it today. Java JDK 11.0.6, Image J 2.0.0-rc-69/1.52p and got a number of errors.

The Fiji Console reports:

[ERROR]: Cannot locate JRE jar in /Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home [ERROR] Cannot create plugin: class='org.scijava.ui.swing.script.languagesupport.JavaLanguageSupportPlugin', priority=0.0, enabled=true, pluginType=LanguageSupportPlugin java.lang.IllegalArgumentException: info cannot be null at org.fife.rsta.ac.java.JarManager.addClassFileSource(JarManager.java:157) at org.fife.rsta.ac.java.JarManager.addCurrentJreClassFileSource(JarManager.java:193) at org.scijava.ui.swing.script.languagesupport.JavaLanguageSupportPlugin.(JavaLanguageSupportPlugin.java:56) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at java.base/java.lang.Class.newInstance(Class.java:584) at org.scijava.plugin.PluginInfo.createInstance(PluginInfo.java:306) at org.scijava.plugin.DefaultPluginService.createInstance(DefaultPluginService.java:237) at org.scijava.plugin.DefaultPluginService.createInstances(DefaultPluginService.java:226) at org.scijava.plugin.DefaultPluginService.createInstancesOfType(DefaultPluginService.java:217) at org.scijava.plugin.AbstractSingletonService.initInstances(AbstractSingletonService.java:138) at org.scijava.plugin.AbstractSingletonService.getInstances(AbstractSingletonService.java:77) at org.scijava.plugin.SingletonService.lambda$initialize$0(SingletonService.java:97) at org.scijava.object.ObjectIndex.resolvePending(ObjectIndex.java:388) at org.scijava.object.ObjectIndex.get(ObjectIndex.java:133) at org.scijava.object.DefaultObjectService.getObjects(DefaultObjectService.java:87) at org.scijava.display.DefaultDisplayService.getDisplays(DefaultDisplayService.java:166) at org.scijava.ui.DefaultUIService.showUI(DefaultUIService.java:159) at org.scijava.ui.DefaultUIService.showUI(DefaultUIService.java:142) at org.scijava.AbstractGateway.launch(AbstractGateway.java:104) at net.imagej.Main.main(Main.java:55) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:279) at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:186) at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:77)

and I get errors in the Terminal as well:

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by net.imagej.patcher.LegacyInjector (file:/Applications/BioInf/Fiji.app/jars/ij1-patcher-0.12.9.jar) to method java.lang.ClassLoader.findLoadedClass(java.lang.String) WARNING: Please consider reporting this to the maintainers of net.imagej.patcher.LegacyInjector WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release Warning: Nashorn engine is planned to be removed from a future JDK release [INFO] Overriding Add Scale Bar ; identifier: script:Calibration/Add_ScaleBar.java; jar: file:/Applications/BioInf/Fiji.app/jars/scijava-common-2.80.1.jar [INFO] Overriding Microscope Scale BF; identifier: script:Calibration/Microscope_Scale_BF.java; jar: file:/Applications/BioInf/Fiji.app/jars/scijava-common-2.80.1.jar [INFO] Overriding Microscope Scale Fluo; identifier: script:Calibration/Microscope_Scale_Fluo.java; jar: file:/Applications/BioInf/Fiji.app/jars/scijava-common-2.80.1.jar [INFO] Overriding Microscope Scale PdM; identifier: script:Calibration/Microscope_Scale_PdM.java; jar: file:/Applications/BioInf/Fiji.app/jars/scijava-common-2.80.1.jar [ERROR]: Cannot locate JRE jar in /Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home [ERROR] Cannot create plugin: class='org.scijava.ui.swing.script.languagesupport.JavaLanguageSupportPlugin', priority=0.0, enabled=true, pluginType=LanguageSupportPlugin java.lang.IllegalArgumentException: info cannot be null at org.fife.rsta.ac.java.JarManager.addClassFileSource(JarManager.java:157) at org.fife.rsta.ac.java.JarManager.addCurrentJreClassFileSource(JarManager.java:193) at org.scijava.ui.swing.script.languagesupport.JavaLanguageSupportPlugin.(JavaLanguageSupportPlugin.java:56) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at java.base/java.lang.Class.newInstance(Class.java:584) at org.scijava.plugin.PluginInfo.createInstance(PluginInfo.java:306) at org.scijava.plugin.DefaultPluginService.createInstance(DefaultPluginService.java:237) at org.scijava.plugin.DefaultPluginService.createInstances(DefaultPluginService.java:226) at org.scijava.plugin.DefaultPluginService.createInstancesOfType(DefaultPluginService.java:217) at org.scijava.plugin.AbstractSingletonService.initInstances(AbstractSingletonService.java:138) at org.scijava.plugin.AbstractSingletonService.getInstances(AbstractSingletonService.java:77) at org.scijava.plugin.SingletonService.lambda$initialize$0(SingletonService.java:97) at org.scijava.object.ObjectIndex.resolvePending(ObjectIndex.java:388) at org.scijava.object.ObjectIndex.get(ObjectIndex.java:133) at org.scijava.object.DefaultObjectService.getObjects(DefaultObjectService.java:87) at org.scijava.display.DefaultDisplayService.getDisplays(DefaultDisplayService.java:166) at org.scijava.ui.DefaultUIService.showUI(DefaultUIService.java:159) at org.scijava.ui.DefaultUIService.showUI(DefaultUIService.java:142) at org.scijava.AbstractGateway.launch(AbstractGateway.java:104) at net.imagej.Main.main(Main.java:55) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:279) at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:186) at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:77)

aschain commented 4 years ago

I found that the minimaven Java 10+ errors seemed to be specific to Windows for me. I was able to run scripts on Fiji running on Java 13 with this change to org.scijava.minimaven: https://github.com/aschain/minimaven/commit/4a0139982ef9bb89398448d44eaa54b5990bb5fe It doesn't seem to effect other systems (not linux at least), or when using Java 1.8. However, it's a bit of a cludge to get it working. I did not figure out why the Coordinate in the MavenProject had malformed Strings.

BarchSteel commented 3 years ago

This may be an old thread, but I tested today with OpenJDK-11.0.9.1+1 and OpenJDK-14.0.2+12 on Windows 10 x64 ImageJ seems to run fine from Eclipse. Apart from the log4j warning, only the following warnings appear when using JDK 11 or JDK 14 instead of JDK 8:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.imagej.patcher.LegacyInjector (file:/.m2/repository/net/imagej/ij1-patcher/1.1.0/ij1-patcher-1.1.0.jar) to method java.lang.ClassLoader.findLoadedClass(java.lang.String)
WARNING: Please consider reporting this to the maintainers of net.imagej.patcher.LegacyInjector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release