在我的项目中,我有两个类 Test1.java 和 Test2.java ,我的目的是以 test1.jar的方式构建两个jar 应仅包含 Tets1.java 且 test2.jar 应仅包含 Tets2.java 。
我在maven程序集插件中添加了排除和包含,但似乎无法正常工作,我在两个罐子中都可以看到 Test1.java 和 Test2.java < / p>
我的 pom.xml 在下面给出
location /forum
{
try_files $uri $uri/ @forum;
}
location @forum
{
rewrite ^/forum(.+)$ /forum/index.php?p=$1 last;
}
更新版本(pom.xml)
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>build-a</id>
<configuration>
<excludes>
<exclude>Test2.java</exclude>
</excludes>
<includes>
<include>Test1.java</include>
</includes>
<archive>
<manifest>
<mainClass>com.example.MyMain</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>test1.jar</finalName>
</configuration>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
<execution>
<id>build-b</id>
<configuration>
<excludes>
<exclude>Test1.java</exclude>
</excludes>
<includes>
<include>Test2.java</include>
</includes>
<archive>
<manifest>
<mainClass>com.example.MyMain</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>test2.jar</finalName>
</configuration>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
答案 0 :(得分:3)
<include>
和<exclude>
是路径元素,因此您需要指定整个路径(或一些通配符),而不仅仅是文件名。 E.g:
<excludes>
<exclude>**/Test2.*</exclude>
</excludes>
<includes>
<include>**/Test1.*</include>
</includes>
答案 1 :(得分:2)
您应该使用自定义assembly.xml
文件。
test1.jar
的示例:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>test1.jar</id>
<formats>
<format>jar</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/java/</directory>
<excludes>
<exclude>**/Test2.*</exclude>
</excludes>
<includes>
<include>**/Test1.*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
在pom.xml
替换:
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
with:
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>