【问题标题】:Build war including WebContent of another project in main service project构建战争,包括主服务项目中另一个项目的 WebContent
【发布时间】:2018-05-24 12:27:25
【问题描述】:

我有一个具有当前文件结构的项目(这工作正常):

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 移动到项目 UI 为:

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

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

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

【问题讨论】:

  • 遵循约定而不是配置范式,而是将内容放入src/main/webapp...

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


【解决方案1】:

你需要一个像这样的父 pom:

<?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,然后是网络战争。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-12
    • 2013-11-17
    • 2015-04-10
    • 2019-01-22
    • 1970-01-01
    • 2018-10-06
    • 2012-06-05
    • 2014-11-23
    相关资源
    最近更新 更多