java Maven、Proguard 和组装问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/880839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven, Proguard and assembly issues
提问by Sway
I'm trying to get Maven working with ProGuard.
我正在尝试让 Maven 与 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.
在我的源文件上运行 ProGuard 并生成混淆类
创建一个引用主类的清单文件,以便我可以将其作为 jar 执行
解压所有相关的库 jar 并创建一个包含它们的巨大 jar。此文件应仅联系 .class 和 .xml 文件。
将它们组装成 .zip 和 tar.gz 文件,其中包括各种 README.txt 文件等。
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
提前致谢,马特
采纳答案by David Rabinowitz
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
最后的 jar 是 finalName-small.jar

