父POM的无效包装必须是“pom”,但是“war”

时间:2017-09-12 12:49:03

标签: java maven maven-3 maven-war-plugin maven-ear-plugin

有人建议我使用以下例外的解决方案。我将创建一个多模块项目。 (战争,耳朵)

pom.xml(战争)

<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>
        <groupId>lu.pgd</groupId>
        <artifactId>WebBusiness</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>WebBusiness-war</artifactId>
    <packaging>war</packaging>
    <name>Web Business</name>

    <properties>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <slf4j.version>1.7.5</slf4j.version>
    </properties>
<build>
        <finalName>webBusiness</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.3</version>
                <configuration>

                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

pom.xml(ear)

<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>
        <groupId>lu.pgd</groupId>
        <artifactId>WebBusiness</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>spdv-ear</artifactId>
    <packaging>ear</packaging>
    <name>Project EAR</name>

    <dependencies>
        <dependency>
            <groupId>lu.pgd</groupId>
            <artifactId>WebBusiness-war</artifactId>
            <version>${project.version}</version>
            <type>war</type>
        </dependency>
    </dependencies>
    <build>
        <finalName>WebBusiness</finalName> 
        <plugins>
            <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.10</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                    <applicationId>WebBusiness</applicationId>
                    <displayName>SPDV (${project.version})</displayName>
                    <modules>
                        <webModule>
                            <groupId>lu.pgd</groupId>
                            <artifactId>WebBusiness-war</artifactId>
                            <contextRoot>/WebBusiness</contextRoot>
                            <moduleId>war</moduleId>
                        </webModule>
                    </modules>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

pom.xml(parent)

<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>lu.pgd</groupId>
    <artifactId>WebBusiness</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Parent Project</name>

    <modules>
        <module>../SPDV_EAR</module>
        <module>../WebBusiness</module>
    </modules>

    <packaging>pom</packaging>
</project>

当我尝试运行Maven Project Parent(Clean + Install)时出现错误:

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Invalid packaging for parent POM lu.pgd:WebBusiness:0.0.1-SNAPSHOT, must be "pom" but is "war" @ lu.pgd:WebBusiness:0.0.1-SNAPSHOT, C:\dev\lu\pgd\WebBusiness\0.0.1-SNAPSHOT\WebBusiness-0.0.1-SNAPSHOT.pom, line 7, column 13
[ERROR] Invalid packaging for parent POM lu.pgd:WebBusiness:0.0.1-SNAPSHOT, must be "pom" but is "war" @ lu.pgd:WebBusiness:0.0.1-SNAPSHOT, C:\dev\lu\pgd\WebBusiness\0.0.1-SNAPSHOT\WebBusiness-0.0.1-SNAPSHOT.pom, line 7, column 13
 @ 
[ERROR] The build could not read 2 projects -> [Help 1]
[ERROR]   
[ERROR]   The project lu.pgd:ccpd-ear:0.0.1-SNAPSHOT (C:\Users\x279\workspace\SPDV_EAR\pom.xml) has 1 error
[ERROR]     Invalid packaging for parent POM lu.pgd:WebBusiness:0.0.1-SNAPSHOT, must be "pom" but is "war" @ lu.pgd:WebBusiness:0.0.1-SNAPSHOT, C:\dev\lu\pgd\WebBusiness\0.0.1-SNAPSHOT\WebBusiness-0.0.1-SNAPSHOT.pom, line 7, column 13
[ERROR]   The project lu.pgd:WebBusiness-war:0.0.1-SNAPSHOT (C:\Users\x279\workspace\WebBusiness\pom.xml) has 1 error
[ERROR]     Invalid packaging for parent POM lu.pgd:WebBusiness:0.0.1-SNAPSHOT, must be "pom" but is "war" @ lu.pgd:WebBusiness:0.0.1-SNAPSHOT, C:\dev\lu\pgd\WebBusiness\0.0.1-SNAPSHOT\WebBusiness-0.0.1-SNAPSHOT.pom, line 7, column 13

有人可以帮我解决这里出了什么问题吗?

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:4)

将模块SPDV_EAR和WebBusiness复制到父项目文件夹(ccpd)中。然后将父pom中的modules标签更改为:

<modules>
    <module>SPDV_EAR</module>
    <module>WebBusiness</module>
</modules>

同样在您的父母pom更改中

<artifactId>WebBusiness</artifactId>

<artifactId>ccpd</artifactId>

在你的战争中(WebBusiness):

  <parent>
    <groupId>lu.pgd</groupId>
    <artifactId>ccpd</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>WebBusiness</artifactId>

在你耳边:

 <parent>
    <groupId>lu.pgd</groupId>
    <artifactId>ccpd</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>SPDV_EAR</artifactId>

因此,您的文件夹名称与项目名称相符。

答案 1 :(得分:1)

通常,多模块项目的文件夹结构如下:

- parent-project-folder
  - pom.xml (parent-project)
  - submodule-project-folder
    - pom.xml (submodule-project)
  - another-submodule-project-folder
    - pom.xml (another-submodule-project)

然后您拥有的父定义就可以了,但是您的子模块旁边有父项目,因此您需要进一步配置。

尝试将relativePath添加到您的父规范中:

<parent>
   <groupId>...
   ...
   <relativePath>path/to/your/parent/pom.xml</relativePath>
</parent>