Proguard is saying it can't find any classes

一世执手 提交于 2019-11-30 14:06:11

ProGuard filters work on file names, so

.....(!META-INF/maven/**,com.myapp.*)

probably won't match any class files. You probably want

.....(!META-INF/maven/**,com/myapp/**)

See ProGuard manual > Usage > File Filters

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:

Notably, class files that are in the WEB-INF/classes directory in a war should be packaged in a jar and put in the WEB-INF/lib directory

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:

<build>
        <plugins>
            <plugin>
                <groupId>com.pyx4me</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>proguard</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <inFilter>com/example/**</inFilter>
                    <libs>
                        <lib>${java.home}/lib/rt.jar</lib>
                        <lib>${java.home}/lib/jsse.jar</lib>
                    </libs>
                    <options>
                        <option>-keep class com.example.echo.EchoServlet</option>
                        <option>-injar ${project.build.directory}/${project.build.finalName}.${project.packaging}</option>
                        <option>-outjar ${project.build.directory}/${project.build.finalName}-proguarded.${project.packaging}</option>
                    </options>
                </configuration>
            </plugin>
        </plugins>
    </build>

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!