Proguard says it cannot find any classes

I am using proguard with spring mvc and maven app.

My pom.xml build section looks like this:

<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 Error 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 that I correctly selected my jar as messages before showing:

 [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 using? This is spring mvc, so I have annotations like:

  • @Autowired
  • @Service
  • @Repository
  • @Controller

Therefore, any of these classes / fields should not be renamed, I would imagine.

(My goal is just to make a headache for someone who decompiles so that they cannot just decompile and use the code. Obfuscating will let them use it, but they won’t be able to maintain the code base if they rewrite it. I don’t have any fantastic algorithms , so I have nothing to hide in this regard.)

Update

Let me clarify here, my spring mvc, using maven for some reason (I'm new to maven) when, when you run mvn clean install, it issues the file myapp.war and the exploded war myapp / (this is what I want to deploy in production, not myapp.war file)

In my myapp folder there is:

 /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 confused in the folder / target / myapp / web -inf / classes? How can I say to do this?

Update 2

I get it now:

OK, I don’t get: the goal failed ... proguard .. Cannot rename / Users / me / dev / git / project1 / myapp / target / myapp / web-inf / classes (see my update 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> 
+7
source share
2 answers

ProGuard filters work with file names, so

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

probably won't match class files. You probably want

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

See ProGuard Guide> Usage> File Filters

+5
source

Can you post all your pom?

Typically, Maven compiles / target / classes (even for WAR files), and the WAR plugin makes a copy in web-inf / classes just before the package phase. You do not have to manually compile classes in web-inf / lib using Maven.

EDITOR: Well, that took a lot of research, but I found the answer for you. Firstly, according to the ProGuard documentation , your military project should not have ANY classes:

It is noteworthy that the class files that are in the WEB-INF / classes directory in the war should be packed in a jar and placed in the WEB-INF / lib directory

You need to reorganize the project so that your web classes are built in a separate bank. After you have created this jar project, you should add it as a dependency in your military project.

Once I created this installation, I was able to successfully build a military 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> 

Pay attention to "com.example.echo.EchoServlet". Since progaurd was about to change the name of my classes, I had to β€œsave” this servlet name so that I could refer to it in the WAR web.xml project. If you are using annotation-based servlet configuration, I guess this is not needed.

+1
source

All Articles