一直以来,我以为 Java 9 以上对 Java 的最大改造是 Module 的问题,今天啪啪啪的打了自己几个耳光,最大的变动,应该是下面这句话
In Java 9 “Application and extension class loaders are no longer instances of java.net.URLClassLoader”, see “Prepare for JDK 9”, Alan Bateman, Oct 2015: http://openjdk.java.net/projects/jigsaw/talks/prepare-for-jdk9-j1-2015.pdf. I'm not sure where exactly the problem lies, if it's in httpunit itself or the JSP compiler libraries, but you might want to run some Java 9 tests yourself. Application and extension class loaders are no longer instances of java.net.URLClassLoader
意思是说,在 Java9 中,应用程序和扩展类都不再是 java.net.URLClassLoader
的实例
这句话的意思,就是如果在 Java 9+ 以上版本中使用了动态加载类,会报错的,比如
Exception in thread "main" java.lang.reflect.InaccessibleObjectException: Unable to make jdk.internal.loader.ClassLoaders$AppClassLoader(jdk.internal.loader.ClassLoaders$PlatformClassLoader,jdk.internal.loader.URLClassPath) accessible: module java.base does not "opens jdk.internal.loader" to unnamed module @520a3426 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:340) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:280) at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:189) at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:182) at org.codehaus.groovy.reflection.CachedConstructor$1.run(CachedConstructor.java:41) at java.base/java.security.AccessController.doPrivileged(Native Method) at org.codehaus.groovy.reflection.CachedConstructor.<init>(CachedConstructor.java:39) at org.codehaus.groovy.reflection.CachedClass$2.initValue(CachedClass.java:76) at org.codehaus.groovy.reflection.CachedClass$2.initValue(CachedClass.java:66) at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46) at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
如果不想降级 Java,又想轻松兼容,也不是没有解决方案,运行代码如下
java --add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-opens jdk.zipfs/jdk.nio.zipfs=ALL-UNNAMED -jar ~/Downloads/jd-gui-1.4.0.jar
你只需要将 ~/Downloads/jd-gui-1.4.0.jar
改成你自己的的 .jar
文件
目前尚无回复