Proguard is saying it can't find any classes

前端 未结 2 665
一个人的身影
一个人的身影 2021-01-02 19:29

I\'m using proguard with a spring mvc application and maven.

My pom.xml\'s build section looks like:


        myapp<         


        
相关标签:
2条回答
  • 2021-01-02 20:04

    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

    0 讨论(0)
  • 2021-01-02 20:05

    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.

    0 讨论(0)
提交回复
热议问题