How to generate an obfuscated jar file for a maven project

leopoldo Iván Villalpando Cruz

I am working on a java application using maven architecture project in Eclipse IDE and java 7

I need to generated an obfuscated a jar file which also must include all the dependencies obfuscated in it I've been checking some solutions around but I´ve been unable to get the desired result.

Some of the places that I've checked are this:

Lin1,Link2, Link3

from the two first links I based most of my current implementation

this is my pom.xml file:

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>modeloconfigurador.cache</groupId>
    <artifactId>CacheClienteModelC</artifactId>
    <version>1.0</version>

    <dependencies>
        <dependency>
            <groupId>modeloconfigurador.cache</groupId>
            <artifactId>Serializer</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
        </dependency>

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.2</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20140107</version>
        </dependency>

        <!--<dependency> -->
        <!--<groupId>com.pyx4me</groupId> -->
        <!--<artifactId>proguard-maven-plugin</artifactId> -->
        <!--<version>2.0.4</version> -->
        <!-- </dependency> -->
        <dependency>
            <groupId>net.sf.proguard</groupId>
            <artifactId>proguard-base</artifactId>
            <version>4.10</version>
        </dependency>


    </dependencies>


    <build>
        <finalName>CacheClienteModelC</finalName>
        <plugins>

            <!-- download source code in Eclipse, best practice -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>false</downloadJavadocs>
                </configuration>
            </plugin>

            <!-- Set a compiler level -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>

                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>

            <!-- Maven Assembly Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <!-- get all project dependencies -->
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <!-- MainClass in mainfest make a executable jar -->
                    <archive>
                        <manifest>
                            <mainClass>main.Main</mainClass>
                        </manifest>
                    </archive>

                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!-- bind to the packaging phase -->
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- comienza configuracion proguard -->


            <plugin>
                <groupId>com.pyx4me</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>proguard</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <proguardVersion>4.10</proguardVersion>
                    <options>

                        <injar>${project.build.finalName}.jar</injar>
                        <outjar>${project.build.finalName}-small.jar</outjar>
                        <!-- <injar>CacheClienteModelC-jar-with-dependencies.jar</injar> -->
                        <!-- <outjar>CacheClienteModelC-small.jar</outjar> -->
                        <option>-allowaccessmodification</option>
                        <option>-keep public class main.Main { *; }</option>
                    </options>
                    <libs>
                        <lib>${java.home}/lib/rt.jar</lib>
                        <lib>${java.home}/lib/jce.jar</lib>
                    </libs>
                </configuration>
                <dependencies>

                    <dependency>
                        <groupId>net.sf.proguard</groupId>
                        <artifactId>proguard-base</artifactId>
                        <version>4.10</version>
                        <!--<version>5.2.1</version> -->
                    </dependency>

                </dependencies>
            </plugin>


            <!-- termina configuracion proguard -->
        </plugins>


    </build>


</project>

the error I'm getting is the following:

[ERROR] Failed to execute goal com.pyx4me:proguard-maven-plugin:2.0.4:proguard (default) on project CacheClienteModelC: Can't rename E:\Users\B267481\Documents\ServidorDesarroCreditoAcertum\CacheClienteModelC\target\CacheClienteModelC.jar -> [Help 1]

EDIT

Just to make things more clear When I build the project, two diferent jars are generated at the target folder (CacheClienteModelC-jar-with-dependecies.jar and CacheClienteModelC.jar), the file that I try to generate is CacheClienteModelC-small.jar (obfuscated jar) which is never created.

How should I configure the plugin to obfuscate my project's file?

Uriel Arvizu

You're using an older version of the proguard plugin for Maven, you should use this one, you can find it in the Maven Central repository.

Now as for your pom.xml, remove from the dependencies the com.pyx4me dependency, you won't need it there.

Now as for the plugin configuration try with something like this:

<plugin>
    <groupId>com.github.wvengen</groupId>
    <artifactId>proguard-maven-plugin</artifactId>
    <version>2.0.10</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>proguard</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <obfuscate>true</obfuscate>
        <injar>${project.build.finalName}.jar</injar>
        <outjar>${project.build.finalName}-small.jar</outjar>
        <includeDependency>true</includeDependency>
        <options>
            <option>-keep public class your.package.Main { *; }</option>
        </options>
        <libs>
            <lib>${java.home}/lib/rt.jar</lib>
            <lib>${java.home}/lib/jce.jar</lib>
        </libs>
        <archive>
            <manifest>
                <mainClass>Main</mainClass>
                <packageName>your.package</packageName>
            </manifest>
        </archive>

    </configuration>
    <dependencies>

        <dependency>
            <groupId>net.sf.proguard</groupId>
            <artifactId>proguard-base</artifactId>
            <version>4.10</version>
            <scope>runtime</scope>
        </dependency>

    </dependencies>
</plugin>

See how you specify the dependency for proguard in it? That should generate the obfuscated jar without problem. Try it out.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to generate a resource to be included in Jar file with maven?

From Dev

How to import github maven project as jar file in Eclipse?

From Dev

How to make the runnable jar file for a maven eclipse project with hibernate configuration

From Dev

How to read properties file from external jar in maven project

From Dev

Generate jar file in Maven with dependencies and tests

From Dev

Is it possible to decompile the jar file obfuscated by proguard?

From Dev

Generate war file from existing maven project

From Dev

Maven does not generate a MANIFEST file with maven jar plugin

From Dev

How to read a javascript file that is obfuscated?

From Dev

How to add dependency to maven project? (How to find out GroupID / ArtifactID from external jar file)

From Java

How to add local jar files to a Maven project?

From Dev

How to make a "fat jar" of a Maven project?

From Dev

How to make a "fat jar" of a Maven project?

From Dev

Generate a jar for maven

From Dev

Maven assembly -- how to create the project JAR with version included, but the artifact tar.gz file without?

From Dev

How to produce a jar file for existing maven project without (no main manifest attribute)?

From Dev

Way to generate javadoc and java project from jar file

From Dev

How to add local project (not jar) as a dependency to a Maven project

From Dev

why I am unable to run this jar file of a maven project?

From Dev

how to generate a checksum for a war file in maven

From Dev

How to include maven dependencies in a jar file?

From Dev

How to move jar file in Maven Library

From Dev

How to access file inside maven shaded jar

From Dev

How to generate build file for project in Netbeans

From Dev

How to use the content of a .jar file as project in Eclipse?

From Dev

How to Create a jar file from github project

From Dev

How to use the content of a .jar file as project in Eclipse?

From Dev

How to add a jar file to a project in android studio

From Dev

How to export a .jar file from a gluon project?

Related Related

  1. 1

    How to generate a resource to be included in Jar file with maven?

  2. 2

    How to import github maven project as jar file in Eclipse?

  3. 3

    How to make the runnable jar file for a maven eclipse project with hibernate configuration

  4. 4

    How to read properties file from external jar in maven project

  5. 5

    Generate jar file in Maven with dependencies and tests

  6. 6

    Is it possible to decompile the jar file obfuscated by proguard?

  7. 7

    Generate war file from existing maven project

  8. 8

    Maven does not generate a MANIFEST file with maven jar plugin

  9. 9

    How to read a javascript file that is obfuscated?

  10. 10

    How to add dependency to maven project? (How to find out GroupID / ArtifactID from external jar file)

  11. 11

    How to add local jar files to a Maven project?

  12. 12

    How to make a "fat jar" of a Maven project?

  13. 13

    How to make a "fat jar" of a Maven project?

  14. 14

    Generate a jar for maven

  15. 15

    Maven assembly -- how to create the project JAR with version included, but the artifact tar.gz file without?

  16. 16

    How to produce a jar file for existing maven project without (no main manifest attribute)?

  17. 17

    Way to generate javadoc and java project from jar file

  18. 18

    How to add local project (not jar) as a dependency to a Maven project

  19. 19

    why I am unable to run this jar file of a maven project?

  20. 20

    how to generate a checksum for a war file in maven

  21. 21

    How to include maven dependencies in a jar file?

  22. 22

    How to move jar file in Maven Library

  23. 23

    How to access file inside maven shaded jar

  24. 24

    How to generate build file for project in Netbeans

  25. 25

    How to use the content of a .jar file as project in Eclipse?

  26. 26

    How to Create a jar file from github project

  27. 27

    How to use the content of a .jar file as project in Eclipse?

  28. 28

    How to add a jar file to a project in android studio

  29. 29

    How to export a .jar file from a gluon project?

HotTag

Archive