有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何构建Maven项目包?

我有5个包裹

com/test1
com/test2
com/test3
com/test4
com/test4

我想一次只构建一个或两个包中的任何一个。我怎样才能做到这一点


共 (1) 个答案

  1. # 1 楼答案

    试试这个罐子:

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

    这就是战争:

    <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>
    (...)