我有5个包裹
com/test1
com/test2
com/test3
com/test4
com/test4
我只想一次只构建一个或两个包中的任何一个。我怎样才能实现这个目标?
最佳答案
对 jar 试试这个:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<excludes>
<exclude>your_package_folder_here/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
这对于 war 来说:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>WEB-INF/classes/your_package_folder_here/**</packagingExcludes>
</configuration>
</plugin>
不要忘记在要排除的包文件夹的完整路径末尾使用 /**
/**
用于文件夹 /*
用于文件。你的 jar 文件将被放置在没有包的目标中。规则适用于这两种情况。
如果您想排除多个包,那么我的第一个建议是先阅读插件 api:
packagingExcludes java.lang.String 2.1-alpha-2 false true The comma separated list of tokens to exclude from the WAR before packaging. This option may be used to implement the skinny WAR use case. Note that you can use the Java Regular Expressions engine to include and exclude specific pattern using the expression %regex[]. Hint: read the about (?!Pattern).
最后你可以看到这个例子:
(...)
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>WEB-INF/classes/com/steelzack/b2b2bwebapp/excludefolder/**,WEB-INF/classes/com/steelzack/b2b2bwebapp/excludefolder2/**</packagingExcludes>
</configuration>
</plugin>
(...)
关于java - 如何明智地构建Maven项目包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37252348/