如何使用 Maven 和 ProGuard 混淆 Web 应用程序

发布于 2024-10-08 14:07:09 字数 2049 浏览 3 评论 0原文

我使用 Maven 和 maven-war-plugin 来构建我的 WAR。所有 JSP 均使用 jspc-maven-plugin 进行预编译,所有类均放入 JAR (WEB-INF/lib) 中。到目前为止一切正常。现在我尝试配置 proguard-maven-plugin 来混淆我的代码。

首先,我尝试在编译阶段混淆所有类,但随后在预编译 JSP 时遇到了麻烦。我找到了一些定义包阶段的示例。但在这种情况下,我不知道如何处理我的 JAR 文件,该文件已经打包到 WAR 中。最后,我尝试将 WAR 设置为mywebapp.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

つ可否回来 2024-10-15 14:07:09

查看可用的 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 to prepare-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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文