imagej2
imagej2 copied to clipboard
Exception in thread "main" java.lang.IllegalArgumentException: Invalid service: net.imagej.legacy.LegacyService
clone this repo to local directory by git-gui, configure project according to "https://imagej.net/develop/intellij". Run/Debug "ImageJ2" shows following exceptions:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid service: net.imagej.legacy.LegacyService
at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:278)
at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:229)
at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:192)
at org.scijava.service.ServiceHelper.loadServices(ServiceHelper.java:164)
at org.scijava.Context.
static {
LegacyInjector.preinit();
}
To debug this issue, start the JVM with the option:
-javaagent:/C:/Users/XXX/.m2/repository/net/imagej/ij1-patcher/1.2.1/ij1-patcher-1.2.1.jar
To enforce pre-initialization, start the JVM with the option:
-javaagent:/C:/Users/XXX/.m2/repository/net/imagej/ij1-patcher/1.2.1/ij1-patcher-1.2.1.jar=init
at net.imagej.patcher.CodeHacker.javaAgentHint(CodeHacker.java:826)
at net.imagej.patcher.LegacyInjector.alreadyPatched(LegacyInjector.java:431)
at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:378)
at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:374)
at net.imagej.legacy.LegacyService.<clinit>(LegacyService.java:141)
... 18 more
Caused by: java.lang.NoSuchFieldException: _hooks at java.base/java.lang.Class.getField(Class.java:2117) at net.imagej.patcher.LegacyInjector.alreadyPatched(LegacyInjector.java:422) ... 21 more
Test environment: OS: windows10 JDK: Oracle JDK 17.0.2 Intellj IDEA: 2021.3.1
debugging by step, it seems:
findLoadedClass.setAccessible(true);
thrown exception at net.imagej.patcher.LegacyInjector
at line 405, don't know if this exception is expected
Did you build ImageJ2 with JDK bundled with it?
In my case, the error occurs when using java 17 (SDK of 'imagej' module)
in Run/Debug Configurations.