xjar
xjar copied to clipboard
jdk9,11不能运行加密后的jar包
写了一个简单的demo,就是打印hello world,发现用jdk8加密后的包,只能用jdk8运行,用jdk9加密后的包,也只能用jdk8跑。
否则会报错:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.xjar.reflection.XReflection (file:/root/tmp9/encrypted9.jar) to field java.net.URLClassLoader.ucp
WARNING: Please consider reporting this to the maintainers of io.xjar.reflection.XReflection
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
Exception in thread "main" java.lang.reflect.InaccessibleObjectException: Unable to make public jdk.internal.loader.Resource jdk.internal.loader.URLClassPath.getResource(java.lang.String) accessible: module java.base does not "exports jdk.internal.loader" to unnamed module @c2e1f26
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.Method.checkCanSetAccessible(Method.java:198)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:192)
at io.xjar.reflection.XReflection.method(XReflection.java:35)
at io.xjar.jar.XJarClassLoader.
goroutine 1 [running]: main.main() /root/tmp9/xjar.go:86 +0x630
总结一下:
加密 | 运行 | 是否报错 jdk8 | jdk8 | 否 jdk8 | jdk11|是 jdk9 |jdk9 |是 jdk9|jdk8 |否
我在网上查了下,说是jdk高版本不支持这个方法,大佬看下高版本jdk有没有替换的方法
这里是在网上对java.lang.reflect.InaccessibleObjectException的答案:https://www.coder.work/article/61641 网上说是jdk9以后引入的一个问题
https://www.itranslater.com/qa/details/2582505421583942656
我也遇到了一样的问题,我是JDK11。但无奈软件要求使用JDK11,因此放弃了XJAR