java - 如何明智地构建Maven项目包?

标签 java maven maven-2

我有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/

相关文章:

java - 在 JList 中锁定选择

java - Jackson 注释不与 Spring boot 一起使用

java - 如何在maven中运行单一集成测试?

maven - followSymlinks 不适用于 maven-clean-plugin

java - Maven 2 & 打包 ejb 与 jar

java - 我如何检测maven 2 jar依赖性?

java - 如何在 Codenameone 中使用 cloudinary 缓存不同名称的图像

java - 在示例 Java 项目中使用数据库的最简单方法?

maven-2 - maven 发布插件 - wagon 因 ssh 身份验证失败,但 snapshort 和发布部署工作 - 嗯?

java - 什么是NullPointerException,我该如何解决?