如何使用 Maven 和 ProGuard 混淆 Web 应用程序
我使用 Maven 和 maven-war-plugin 来构建我的 WAR。所有 JSP 均使用 jspc-maven-plugin 进行预编译,所有类均放入 JAR (WEB-INF/lib) 中。到目前为止一切正常。现在我尝试配置 proguard-maven-plugin 来混淆我的代码。
首先,我尝试在编译阶段混淆所有类,但随后在预编译 JSP 时遇到了麻烦。我找到了一些定义包阶段的示例。但在这种情况下,我不知道如何处理我的 JAR 文件,该文件已经打包到 WAR 中。最后,我尝试将 WAR 设置为
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<includeDependency>false</includeDependency>
<injar>${project.artifactId}-v${project.version}.war</injar>
<outjar>${project.artifactId}-v${project.version}-obf.war</outjar>
<outputDirectory>${project.build.directory}</outputDirectory>
<maxMemory>256m</maxMemory>
<libs>
<!-- Java Runtime -->
<lib>${java.home}/../Classes/classes.jar</lib>
<lib>${java.home}/../Classes/jce.jar</lib>
</libs>
<options>
<option>-allowaccessmodification</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-dontskipnonpubliclibraryclassmembers</option>
</options>
</configuration>
</plugin>
您有任何提示、示例来完成此任务吗?
多谢! 大卫
I use Maven and the maven-war-plugin to to build my WAR. All JSPs are pre-compiled using the jspc-maven-plugin and all classes are put into a JAR (WEB-INF/lib). So far everything works fine. Now I try to configure the proguard-maven-plugin to obfuscate my code.
First I tried to obfuscate all classes during the compile phase but then I get in trouble pre-compiling the JSPs. I found some examples where the package phase is defined. But in this case I dont know how to address my JAR file, which is alrady packed into the WAR. Finally I tried simply to set my WAR as <injar>mywebapp.war</injar>. But this is also not working. What am I missing?
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<includeDependency>false</includeDependency>
<injar>${project.artifactId}-v${project.version}.war</injar>
<outjar>${project.artifactId}-v${project.version}-obf.war</outjar>
<outputDirectory>${project.build.directory}</outputDirectory>
<maxMemory>256m</maxMemory>
<libs>
<!-- Java Runtime -->
<lib>${java.home}/../Classes/classes.jar</lib>
<lib>${java.home}/../Classes/jce.jar</lib>
</libs>
<options>
<option>-allowaccessmodification</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-dontskipnonpubliclibraryclassmembers</option>
</options>
</configuration>
</plugin>
Do you have any hints, examples to get this done?
Thanks a lot!
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看可用的 Maven 生命周期。特别是默认生命周期。您可能遇到的问题是 Maven 可以保证某些插件(例如 jar 和 war 插件),但其他插件(例如您的 proguard 插件)可能无法保证。
我认为如果您将执行阶段从
package
更改为prepare-package
,那么 JSP 文件应该在打包到 JAR 文件并随后打包到 WAR 之前进行混淆文件。该阶段不应干扰您可能拥有的任何类的编译。Take a look at the Maven lifecycles that are available. Specifically the default lifecycle. The problem you may be running into is that Maven can guarantee on some plugins, like the jar and war plugins, but others plugins, like your proguard plugin, it may not.
I think if you changed the execution phase from
package
toprepare-package
, that should get the JSP files obfuscated before they are packaged into the the JAR file and subsequently into the WAR file. And that phase should not interfere with with compilation of any classes you may have.