gpt4 book ai didi

java - 排除和包含在 Maven 程序集插件中不起作用

转载 作者:行者123 更新时间:2023-11-30 06:06:16 24 4
gpt4 key购买 nike

在我的项目中,我有两个类 Test1.javaTest2.java,我的目的是以 test1.jar 的方式构建两个 jar 应仅包含 Tets1.java,而 test2.jar 应仅包含 Tets2.java

我在 Maven 程序集插件中添加了排除和包含,但它似乎不起作用,在两个 jar 中我都可以看到 Test1.javaTest2.java

我的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>

更新版本 (pom.xml)

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>build-a</id>
<configuration>
<excludes>
<exclude>**/Test.*</exclude>
</excludes>
<includes>
<include>**/Test1.*</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>**/Test.*</exclude>
</excludes>
<includes>
<include>**/Test2.*</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>

最佳答案

<include><exclude>是路径元素,因此您需要指定整个路径(或一些通配符),而不仅仅是文件名。例如:

<excludes>
<exclude>**/Test2.*</exclude>
</excludes>
<includes>
<include>**/Test1.*</include>
</includes>

关于java - 排除和包含在 Maven 程序集插件中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44601860/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com