我正在尝试解压缩maven工件A并将其重新打包到maven项目B中的新jar文件中。
将工件A中的类文件解压缩到:
<my.classes.folder>${project.build.directory}/staging</my.classes.folder>
使用此工作正常:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.test</groupId>
<artifactId>mvn-sample</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${my.classes.folder}</outputDirectory>
<includes>**/*.class,**/*.xml</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
在同一个pom中,我现在想要生成一个包含刚刚解压缩的类的附加jar:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesdirectory>${my.classes.folder}</classesdirectory>
<classifier>sample</classifier>
</configuration>
</execution>
</executions>
</plugin>
创建了一个新jar,但它不包含以下类:
${my.classes.folder}
它只是默认项目jar的副本。有什么想法吗?
我试图遵循本指南:
http://jkrishnaraotech.blogspot.dk/2011/06/unpack-remove-some-classes-and-repack.html
但它不起作用。
答案 0 :(得分:7)
我建议你改用maven-shade-plugin
。
这将使unpack-repack在同一个调用中。
你可以这样做:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>com.test:mvn-sample:1.0.0-SNAPSHOT</artifact>
<includes>
<include>**/*.class</include>
<include>**/*.xml</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
答案 1 :(得分:3)
在您拥有<classesdirectory>
的示例中,docs的元素为<classesDirectory>
。我认为区分大小写非常重要。