无法将包装作为pom.xml中的war添加到Eclipse中的Maven项目中

时间:2019-04-10 04:23:37

标签: java eclipse maven

我是Maven的新手。我一直在使用pom.xml在Eclipse中进行Maven项目,如下所示:

 <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>com.walmart.move.nim.damage</groupId>
 <artifactId>damages-external-services-parent</artifactId>
 <version>1.0.36-SNAPSHOT</version>
 <packaging>war</packaging> #### THIS LINE IS GIVING ERROR
</parent>
<artifactId>damages-external-services</artifactId>
<name>damages-external-services</name>
<description>Damages external services. This is the war.</description>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
<springframework.version>4.3.4.RELEASE</springframework.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.javadoc.skip>true</maven.javadoc.skip>

</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${springframework.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jdbc</artifactId>
        <version>7.0.62</version>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.walmart.move.nim.damage</groupId>
        <artifactId>damages-utils</artifactId>
        <version>1.0.2214</version>
        <!-- <version>1.0.4-SNAPSHOT</version> -->
    </dependency>
</dependencies>

由于上述包装线,在Eclipse中执行mvn clean安装时,出现以下错误:

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Malformed POM /Users/a0m0466/workspace/damage.damages-orchestrator.dc-external-services/damages-external-services/pom.xml: Unrecognised tag: 'packaging' (position: START_TAG seen ...</version>\n    <packaging>... @7:16)  @ /Users/a0m0466/workspace/damage.damages-orchestrator.dc-external-services/damages-external-services/pom.xml, line 7, column 16
  @
 [ERROR] The build could not read 1 project -> [Help 1]
 [ERROR]
 [ERROR]   The project com.walmart.move.nim.damage:damages-external-services:1.0.36-SNAPSHOT (/Users/a0m0466/workspace/damage.damages-orchestrator.dc-external-services/damages-external-services/pom.xml) has 1 error
  [ERROR]     Malformed POM /Users/a0m0466/workspace/damage.damages-orchestrator.dc-external-services/damages-external-services/pom.xml: Unrecognised tag: 'packaging' (position: START_TAG seen ...</version>\n    <packaging>... @7:16)  @ /Users/a0m0466/workspace/damage.damages-orchestrator.dc-external-services/damages-external-services/pom.xml, line 7, column 16 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/ModelParseException

2 个答案:

答案 0 :(得分:2)

可以使用包装 pom 声明父POM。它不打算被分发,因为它仅从其他项目中引用。

Maven父pom可以包含几乎所有内容,并且可以将其继承到子pom文件中,例如

父母POM

<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.demo</groupId>
    <artifactId>Examples</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>Parent POM</name>
    <url>http://maven.apache.org</url>

    <properties>

....

儿童POM

<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/maven-v4_0_0.xsd">

    <!--The identifier of the parent POM-->
    <parent>
        <groupId>com.demo</groupId>
        <artifactId>Examples</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>Examples</artifactId>
    <name>Child POM</name>
    <packaging>jar</packaging>

    <dependencies>        
....

有关更多参考,https://howtodoinjava.com/maven/maven-parent-child-pom-example/

答案 1 :(得分:1)

包装<packaging>标签应位于</parent>标签之外。

</parent>
<packaging>war</packaging>