使用maven-ear-plugin创建war文件并在一个pom.xml中定义它

时间:2011-04-12 16:10:48

标签: maven war

我处于maven使用的起始级别。我希望我能清楚地解释我的问题,我想创建一个包含war文件的ear文件。我计划从一开始就用来创建一个war文件。另外我想在我的项目的pom.xml中执行它,并且只有一个pom.xml,这是问题所在;

  1. 我可以创建一个ear文件,其中包含我在一个pom.xml文件中同时创建的这场战争吗?
  2. 当我尝试在webmodule标签中创建war文件时,遇到的问题是“Artifact [war:denem.denem:denem]不是项目的依赖项。”我理解这就是为什么我在同一个pom.xml中添加了这个文件的依赖,但这次我遇到了这个问题
  3. (顺便说一句,我建立这个pom的命令是“mvn clean package”)

    “缺少1个必需的工件。

    for artifact:

    com.denem.denem:com.denem.de2:ear:v0.1"
    

    它试图找到这个war文件,但我想创建它而不是找到它。这是我的pom.xml文件中的代码;

    <parent>
        <groupId>denem.denem</groupId>
        <artifactId>com.denem.denem</artifactId>
        <version>v0.1</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>denem.denem</groupId>
    <artifactId>com.denem.de2</artifactId>
    <version>v0.1</version>
    
    <packaging>ear</packaging>
    
    <properties>
        <cxf.version>2.2.5</cxf.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>denem.denem</groupId>
            <artifactId>denem</artifactId>
            <version>v0.1</version>
            <type>war</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
    
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <finalName>edu</finalName>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                    <modules>
                        <webModule>
                            <groupId>denem.denem</groupId>
                            <artifactId>denem</artifactId>
                            <contextRoot>/WebContent</contextRoot>
                        </webModule>
                    </modules>
                </configuration>
            </plugin>
    
        </plugins>
    </build>
    

    我想我做了很多错事。但如果你能帮助我,我会很高兴。无论如何,谢谢你。

1 个答案:

答案 0 :(得分:2)

您需要创建一个模块化项目。 创建:

  1. “pom”类型的父项目;
  2. “战争”类型的儿童项目;
  3. 如果需要,“ejb”类型的子项目;
  4. 如果需要,可以使用“jar”类型的子项目(通用库);
  5. 一个类型为“ear”的项目,它具有以上所有依赖项。
  6. 在后者中,您需要配置耳塞,放置您需要的所有模块。