构建战争,包括主服务项目

时间:2018-05-24 12:27:26

标签: maven maven-2 maven-3 maven-plugin maven-war-plugin

我有一个具有当前文件结构的项目(这很好):

project-services
    - src/main/java
    - WebContent
    - pom.xml

项目服务pom.xml

...
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
...

我必须将项目服务的WebContent移动到project-ui:

project-services
    - src/main/java
    - pom.xml
project-ui
    - pom.xml
    - WebContent

现在我必须在WebContent中建立包括project-ui project-services的战争。

我需要在project-services's pom.xml中进行哪些修改才能像之前一样工作?

1 个答案:

答案 0 :(得分:0)

你需要像这样的父母:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.greg</groupId>
    <artifactId>multi-module-example</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>multi-module-example</name>

    <modules>
        <module>services</module>
        <module>web</module>
    </modules>

</project>

有2个项目,一个用于服务,一个用于webapp

<?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <artifactId>multi-module-example</artifactId>
            <groupId>com.greg</groupId>
            <version>1.0-SNAPSHOT</version>
        </parent>

        <artifactId>services</artifactId>

        <dependencies>
            <!-- dependencies -->
        </dependencies>

    </project>

然后,web pom依赖于项目版本的服务

如前所述,请遵守目录结构的maven约定。

<?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <artifactId>multi-module-example</artifactId>
            <groupId>com.greg</groupId>
            <version>1.0-SNAPSHOT</version>
        </parent>

        <artifactId>web</artifactId>
        <packaging>war</packaging>

        <dependencies>
            <dependency>
                <groupId>com.greg</groupId>
                <artifactId>services</artifactId>
                <version>${project.version}</version>
            </dependency>
            <!-- other dependencies -->
        </dependencies>

        <build>
            <finalName>web</finalName>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>

当你构建父级时,它将构建服务jar,然后是web war。