问题描述
我正在使用IntelliJ IDEA作为IDE开发JavaFX应用程序.
I'm developing a JavaFX application using IntelliJ IDEA as the IDE.
到目前为止,一切运行顺利,我已配置了所有外部库并正确创建了JavaFX工件.
So far, everything runs smoothly, I have all my external libs configured and my JavaFX artifact being correctly created.
现在,我想在创建工件时集成混淆处理(使用Proguard).
Now I would like to integrate obfuscation (using Proguard) when the artifact is created.
IntelliJ在工件的属性中具有预处理"和后处理"选项,我可以在其中定义要运行的Ant任务.
IntelliJ have a 'Pre-processing' and 'Post-processing' option in artifact's properties where I can define an Ant task to be runned.
但是我不知道如何创建该任务并告诉编译器我的混淆选项.
But I have no idea how to create that task and tell the compiler my obfuscation options.
非常感谢您提供任何线索,
Thank you very much in advance for any clues,
最诚挚的问候
推荐答案
有3种基本方法:
- 创建一个普通的proguard.cfg文件,并从ant引用它
- 使用XML表示法将您的proguard设置直接放在ant内
- 使用proguard.cfg格式将您的proguard设置直接放在ant内
这是在第3种方法中将Proguard与Ant结合使用的基本示例: http://www.reviewmylife.co.uk/blog/2007/10/20/proguard-eclipse-ant-buildxml/
Here's a basic example of using Proguard with Ant with the 3rd approach:http://www.reviewmylife.co.uk/blog/2007/10/20/proguard-eclipse-ant-buildxml/
关于Proguard,要记住的重要一点是,要混淆的所有内容都必须在JAR文件中,并且您需要明确告诉它不要混淆某些内容(例如程序入口点,通过反射等).
The important thing to remember about Proguard is that everything you want to obfuscate has to be inside a JAR file, and you'll need to explicitly tell it not to obfuscate certain things (like your program entry point, things you access via reflection, etc).
JavaFX创建一个文件作为您要防止混淆的入口点:
JavaFX creates a file used as an entry point you want to prevent obfuscating:
-keepclasseswithmembers public class com.javafx.main.Main {
public *; public static *;
}
确保包含Java/JavaFX库
Make sure to include Java/JavaFX libs
-libraryjars "${java.home}/lib/rt.jar"
-libraryjars "${java.home}/lib/ant-javafx.jar"
-libraryjars "${java.home}/lib/jfxrt.jar"
如果您使用的是FXML文件,则需要确保FXML文件的重命名与其各自的控制器文件类似:
If you're using FXML files, you'll want to make sure your FXML files are renamed similarly to their respective controller file:
-adaptresourcefilecontents **.fxml
任何带有@FXML注释的内容都可以通过反射进行访问,因此请不要混淆它们:
Anything annotated with @FXML is accessed through reflection, so don't obfuscate them:
-keepclassmembernames class * {
@javafx.fxml.FXML *;
}
Proguard网站上有很多信息,但是很难理解.
The Proguard website has a lot of information, but it can be difficult to grok.
老实说,网络上有很多示例向您展示如何执行此操作.只是google javafx proguard,您可能会找到一些很好的完整示例.
Honestly, there are plenty of examples on the web that show you how to do this. Just google javafx proguard, and you'll probably find some good complete examples.
关于IntelliJ如何将信息传递给Ant ..我不知道.它可能传递了一些变量,您像普通的Ant一样正确地引用了它们.我敢肯定,如果您在网上找不到JetBrains网站上的信息,则可以在其网站上找到.
as far as how IntelliJ passes information to Ant.. I don't know. There are probably some variables it passes in that you reference like a normal Ant propertly. I'm sure JetBrains website has info on that on their website if you can't find it on the net.
如果是我,我将创建一个ant脚本来编译我的应用程序而不会产生混淆,然后在解决问题后添加proguard.
If it was me, I'd just create an ant script to compile my application without obfuscation, then add in proguard once you've got that squared away.
这篇关于如何将Proguard模糊处理集成到我的JavaFX的IntelliJ工件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!