简体   繁体   English

如何在 Proguard 中包含 java.desktop 模块作为库 jar

[英]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.

相关问题 java.desktop 无法解析为模块 - java.desktop cannot be resolved to a module 模块java.base不读取模块java.desktop - module java.base does not read module java.desktop 如何在ProGuard中混淆库jar? - How to obfuscate a library jar in ProGuard? When this error occurs Error:(1, 1) java: module JavaFX reads package java.awt from both java.desktop and java.datatransfer - When this error occurs Error:(1, 1) java: module JavaFX reads package java.awt from both java.desktop and java.datatransfer JavaFX中的JavaBeanProperties,而无需拉入java.desktop(Swing,AWT) - JavaBeanProperties in JavaFX without pulling in java.desktop (Swing, AWT) mailto URI在Java.Desktop和Windows / MS Outlook之间被截断 - mailto URI truncated between Java.Desktop and Windows/MS outlook 如何防止 ProGuard 混淆从 JAR 文件导入的库? - How to prevent ProGuard from obfuscating a library imported from a JAR file? 如何在Java项目中包含.jar库,并在编译后使应用程序使用该库在应用程序内部? - How to include .jar library, that is inside java project and make application use this library that is inside application after compilation? 如何将 ProGuard 用于 Eclipse Java 桌面应用程序? - How do I use ProGuard for Eclipse Java desktop applications? 如何以OS独立的方式在Proguard配置中包含rt.jar / classes.jar? - How to include rt.jar/classes.jar in Proguard configuration in an OS independant way?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM