在Maven中构建EAR文件时出错

时间:2012-10-11 10:04:18

标签: maven maven-ear-plugin

我正面临以下问题:

  

无法执行目标   org.apache.maven.plugins:Maven的耳插件:2.7:生成的应用程序的XML   项目UserAdminEAR上的(default-generate-application-xml):   工件[war:com.syril.administration:UserAdmin]不是依赖项   该项目。 - > [帮助1]

这种错误的解决方案是什么?

我的pom.xml是

<modelVersion>4.0.0</modelVersion>
<groupId>UserAdminEAR</groupId>
<artifactId>UserAdminEAR</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>UserAdmin</name>
<packaging>ear</packaging>
<dependencies>
    <dependency>
        <groupId>com.syril.dao</groupId>
        <artifactId>dataAccess</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.syril.service</groupId>
        <artifactId>UserAdminService</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>war</type>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <modules>
                    <jarModule></jarModule>
                    <javaModule>
                        <groupId>com.syril.dao</groupId>
                        <artifactId>dataAccess</artifactId>
                        <includeInApplicationXml>true</includeInApplicationXml>
                    </javaModule>
                    <webModule>
                        <groupId>com.syril.service</groupId>
                        <artifactId>UserAdminSL</artifactId>
                        <contextRoot>/UserAdminSL</contextRoot>
                    </webModule>
                </modules>
            </configuration>
        </plugin>
    </plugins>
</build>

1 个答案:

答案 0 :(得分:16)

您还必须将war作为依赖项添加到项目中,而不仅仅是在插件配置中。

<project ...>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.syril.administration</groupId>
    <artifactId>UserAdminEAR</artifactId> 
    <version>YOUR_VERSION_HERE</version>
    <packaging>ear</packaging>

    <dependencies>
        <!-- some other dependencies here -->
        ...
        <!-- Here is the dependency to the war that is referenced in the ear plugin -->
        <dependency> 
            <groupId>com.syril.administration</groupId> 
            <artifactId>UserAdmin</artifactId> 
            <version>YOUR_VERSION_HERE</version> 
            <type>war</type> 
        </dependency>
    </dependencies>
    ...
</project>

修改

<webModule/>工件不在您的<dependencies/>列表中。这就是我的建议。

添加以下内容:

<dependency>
    <groupId>com.syril.service</groupId>
    <artifactId>UserAdminSL</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <type>war</type>
</dependency>

更改<webModule/>

<webModule>
    <groupId>com.syril.service</groupId>
    <artifactId>UserAdminService</artifactId>
    <contextRoot>/UserAdminSL</contextRoot>
</webModule>

当然,如果我认为UserAdminServiceUserAdminSL相同,那就是这样。