[英]How to include java.desktop module as a library jar in Proguard
I use proguard to obfuscate an application in Java 11 (latest LTS version) using the proguard gradle plugin.我使用 proguard 使用 proguard gradle 插件来混淆 Java 11(最新 LTS 版本)中的应用程序。 This is the dependency currently.
这是当前的依赖。 I would like to comment that I have to use a version >= 7.1.0-beta3 for other reasons that have to do with the project.
我想评论一下,由于与项目有关的其他原因,我必须使用 >= 7.1.0-beta3 的版本。 However this issue is not related to that.
但是,这个问题与此无关。
com.guardsquare:proguard-gradle:7.1.0-beta4
Recently a dependency on interface
javax.swing.tree.TreeNode module was added.最近添加了对
interface
javax.swing.tree.TreeNode 模块的依赖。 The javax.swing.tree.TreeNode module is part of the java.desktop module . javax.swing.tree.TreeNode 模块是java.desktop模块的一部分。
I use the following code to include the JDK libraries in java version independent way.我使用以下代码以 java 版本独立方式包含 JDK 库。 Following the proguard examples .
以下proguard示例。
if (System.getProperty('java.version').startsWith('1.')) {
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
} else {
libraryjars "${System.getProperty('java.home')}/jmods/java.base.jmod", jarfilter: '!**.jar', filter: '!module-info.class'
}
However I get the following warning:但是我收到以下警告:
Warning: a.custom.CustomClass: can't find referenced class javax.swing.tree.TreeNode
Execution failed for task ':obfuscation_task'.
> java.io.IOException: Please correct the above warnings first.
What does proguard need to 'see' the javax.swing.tree.TreeNode
class
as a libraryclass? proguard 需要什么才能将
javax.swing.tree.TreeNode
class
作为库类“看到”?
I found the solution as I was trying to add details to the question.我在尝试向问题添加详细信息时找到了解决方案。
The reason for the error is that starting from Java 9 you have to explicitly specify which modules are added.错误的原因是从 Java 9 开始您必须明确指定添加哪些模块。 The code in the question just adds the
java.base
module.问题中的代码只是添加了
java.base
模块。 To add the java.desktop
module the following line should be added:要添加
java.desktop
模块,应添加以下行:
libraryjars "${System.getProperty('java.home')}/jmods/java.desktop.jmod", jarfilter: '!**.jar', filter: '!module-info.class'
The full part of java library inclusion is now: java 库包含的完整部分现在是:
if (System.getProperty('java.version').startsWith('1.')) {
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
} else {
libraryjars "${System.getProperty('java.home')}/jmods/java.base.jmod", jarfilter: '!**.jar', filter: '!module-info.class'
libraryjars "${System.getProperty('java.home')}/jmods/java.desktop.jmod", jarfilter: '!**.jar', filter: '!module-info.class'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.