Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

java - Maven, Proguard and assembly issues

I'm trying to get Maven working with ProGuard.

What I want to achieve is the following:

  • Run ProGuard over my source files and produce obfuscated classes

  • Create a manifest file that references the main class so that I can execute it as a jar

  • Unpack all of the associated library jars and create one huge jar containing them all. This file should only contact .class and .xml files only.

  • Assemble them into .zip and tar.gz files that include various README.txt files and so on.

So far I've got something like this:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.class.path.MainClass</mainClass>
                    </manifest>
                </archive>
                <includes>
                    <include>**/*.class</include>
                    <include>**/*.xml</include>
                </includes>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.pyx4me</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <configuration>
                <options>
                    <option>-allowaccessmodification</option>
                </options>
                <obfuscate>true</obfuscate>
                <injar>classes</injar>
                <outjar>${project.build.finalName}.jar</outjar>
                <outputDirectory>${project.build.directory}</outputDirectory>
                <proguardInclude>src/main/assembly/proguard.conf</proguardInclude>
                <libs>
                    lib/rt.jar</lib>
                </libs>
            </configuration>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>proguard</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>assembly</goal>
                    </goals>
                    <configuration>
                        <descriptors>
                            <descriptor>
                                src/main/assembly/bin.xml
                            </descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>

But I'm having no joy. Can anyone give me any vague pointers on this?

Thanks in advance, Matt

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is the configuration that had worked for me

<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>-allowaccessmodification</option>
            <option>-keep public class com.class.path.MainClass { public *; public static *; }</option>
        </options>
        <injar>${project.build.finalName}.jar</injar>
        <outjar>${project.build.finalName}-small.jar</outjar>
        <outputDirectory>${project.build.directory}</outputDirectory>
        <libs>
            <lib>${java.home}/lib/rt.jar</lib>
            <lib>${java.home}/lib/jsse.jar</lib>
        </libs>
        <addMavenDescriptor>false</addMavenDescriptor>
    </configuration>
</plugin>

The final jar is the finalName-small.jar


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...