Proguard 说它找不到任何类
我将 proguard 与 spring mvc 应用程序和 Maven 一起使用。
我的 pom.xml 的构建部分如下所示:
<build>
<finalName>myapp</finalName>
<plugins>
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<!--<options>-->
<!--<option>-keep public class</option>-->
<!--</options>-->
<injar>${project.build.finalName}</injar>
<injar>${project.build.finalName}</injar>
<inFilter>com.myapp.*</inFilter>
</configuration>
</plugin>
</plugins>
我也尝试过:
<injar>${project.build.finalName}.war</injar>
当我运行时:
mvn clean install
构建失败消息:
[proguard] Reading program war [/Users/me/dev/git/myproject/myapp/target/myapp.war] (filtered)
[proguard] Error: The input doesn't contain any classes. Did you specify the proper '-injars' options?
ERROR] Failed to execute goal com.pyx4me:proguard-maven-plugin:2.0.4:proguard (default) on project myapp: Obfuscation failed (result=1) -> [Help 1]
它似乎已正确拾取我的 jar,如显示之前的消息:
[INFO] --- proguard-maven-plugin:2.0.4:proguard (default) @ myapp ---
[INFO] execute ProGuard [-injars, '/Users/me/dev/gitserver/myproject/myapp/target/myapp.war'(!META-INF/maven/**,com.myapp.*), -outjars, '/Users/me/dev/git/myproject/myapp/target/myapp_pg.war', -libraryjars, ....
此外,您建议我使用什么选项?< /strong> 这是一个 spring mvc,所以我有这样的注释:
- @Autowired
- @Service
- @Repository
- @Controller
所以我想这些类/字段中的任何一个都不应该被重命名。
(我的目标只是让反编译的人感到头疼,这样他们就不能反编译并使用代码。混淆会让他们使用它,但他们将无法维护代码库,除非他们重新 -我没有任何花哨的算法,所以在这方面我没有什么可隐藏的。)
更新
让我在这里说清楚,我的 spring mvc 由于某种原因使用 maven (我是新手)到maven)当做一个mvn clean install 会生成 myapp.war 文件和分解的 war myapp/ (这是我想要在生产中部署的文件,而不是 myapp.war 文件)
我的 myapp 文件夹有:
/target/myapp/
/target/myapp/meta-inf (empty folder)
/target/myapp/web-inf
/target/myapp/web-inf/classes (com.myapp. ...)
/target/myapp/web-inf/lib/
/target/myapp/web-inf/ web.xml, application.xml (for spring)
/target/myapp/web-inf/views/
所以 proguard 应该在 /target/myapp 中进行混淆/web-inf/classes 文件夹对吧? 我如何告诉它这样做?
更新2
我现在得到这个:
好的,我没有得到:无法执行目标...proguard ..无法重命名/Users/me/dev/git/project1/myapp/ target/myapp/web-inf/classes (请参阅我的更新部分,了解我在 pom.xml 中更改的内容)
我将 pom.xml 更改为:
<configuration>
<obfuscate>true</obfuscate>
<injar>${project.build.finalName}/WEB-INF/classes/</injar>
<inFilter>com/myapp/**</inFilter>
</configuration>
I'm using proguard with a spring mvc application and maven.
My pom.xml's build section looks like:
<build>
<finalName>myapp</finalName>
<plugins>
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<!--<options>-->
<!--<option>-keep public class</option>-->
<!--</options>-->
<injar>${project.build.finalName}</injar>
<injar>${project.build.finalName}</injar>
<inFilter>com.myapp.*</inFilter>
</configuration>
</plugin>
</plugins>
I also tried:
<injar>${project.build.finalName}.war</injar>
When I run:
mvn clean install
Build failure message:
[proguard] Reading program war [/Users/me/dev/git/myproject/myapp/target/myapp.war] (filtered)
[proguard] Error: The input doesn't contain any classes. Did you specify the proper '-injars' options?
ERROR] Failed to execute goal com.pyx4me:proguard-maven-plugin:2.0.4:proguard (default) on project myapp: Obfuscation failed (result=1) -> [Help 1]
It seems to have picked up my jar correctly as the messages before show:
[INFO] --- proguard-maven-plugin:2.0.4:proguard (default) @ myapp ---
[INFO] execute ProGuard [-injars, '/Users/me/dev/gitserver/myproject/myapp/target/myapp.war'(!META-INF/maven/**,com.myapp.*), -outjars, '/Users/me/dev/git/myproject/myapp/target/myapp_pg.war', -libraryjars, ....
Also, what options do you suggest I use? This is a spring mvc so I have annotations like:
- @Autowired
- @Service
- @Repository
- @Controller
So any of those classes/fields should not be renamed I would imagine.
(My goal is just to make it a headache to someone who decompiles, such that they can't just decompile and use the code. Obfuscating will let them use it, but they won't be able to maintain the codebase unless they re-write it. I don't have any fancy algorithms so I have nothing really to hide in that respect.)
Update
Let me be clear here, my spring mvc using maven for some reason (I'm new to maven) when doing a mvn clean install produces both a myapp.war file and a exploded war myapp/ (this is what I want to deploy in production, not the myapp.war file)
My myapp folder has:
/target/myapp/
/target/myapp/meta-inf (empty folder)
/target/myapp/web-inf
/target/myapp/web-inf/classes (com.myapp. ...)
/target/myapp/web-inf/lib/
/target/myapp/web-inf/ web.xml, application.xml (for spring)
/target/myapp/web-inf/views/
So proguard should be obfuscating in the /target/myapp/web-inf/classes folder right?
How do I tell it to do so?
Update 2
I'm getting this now:
OK, I am not getting: failed to execute goal ...proguard .. Can't rename /Users/me/dev/git/project1/myapp/target/myapp/web-inf/classes (see my updates section for what I changed in my pom.xml)
I changed my pom.xml with:
<configuration>
<obfuscate>true</obfuscate>
<injar>${project.build.finalName}/WEB-INF/classes/</injar>
<inFilter>com/myapp/**</inFilter>
</configuration>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ProGuard 过滤器适用于文件名,因此
可能不会匹配任何类文件。您可能需要
参阅 ProGuard 手册 >使用方法>文件过滤器
ProGuard filters work on file names, so
probably won't match any class files. You probably want
See ProGuard manual > Usage > File Filters
你能发布你的整个pom吗?
通常,Maven 编译到 /target/classes (即使是 WAR 文件),并且 WAR 插件会在打包阶段之前将其复制到 web-inf/classes。您不应该使用 Maven 手动将类编译到 web-inf/lib。
编辑:好的,这需要大量的研究,但我已经为你找到了答案。首先,根据 ProGuard 文档,您不应该有任何< /strong> 你的战争项目中的类:
您需要重构您的项目,以便您的 Web 类构建在一个单独的 jar 中。构建该 jar 项目后,必须将其添加为 war 项目中的依赖项。
创建该设置后,我成功地使用以下配置构建了一个 war 项目:
请注意“com.example.echo.EchoServlet”。由于 progaurd 将更改我的类的名称,因此我必须“保留”此 servlet 名称,以便我可以在 WAR 项目的 web.xml 中引用它。如果您使用基于注释的 servlet 配置,我想这是没有必要的。
Can you post your entire pom?
Normally, Maven compiles to /target/classes (Even for WAR files) and the WAR plugin does the copy to web-inf/classes right before the package phase. You should not be manually compiling classes to web-inf/lib with Maven.
EDIT: OK this has take quite a bit of research, but I've found an answer for you. First, according to the ProGuard documentation, you should not have ANY classes in your war project:
You need to refactor your project so your web classes are built in a separate jar. Once you have built that jar project, you must add it as a dependency in your war project.
Once I created that setup, I was successfully able to build a war project with the following configuration:
Note the "com.example.echo.EchoServlet". Since progaurd was going to change the name of my classes, I had to "keep" this servlet name so I could reference it in the WAR project's web.xml. If you use annotation based servlet configuration, I imagine this won't be necessary.