Java 带有 ejb 模块的 Maven 耳朵项目。生成 application.xml 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19885358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 21:01:58  来源:igfitidea点击:

Maven ear project with ejb module. error generating application.xml

javamavenconfiguration

提问by coderatchet

when compiling the following pom, I get an exception stating that the coredependency is missing from the project:

编译以下 pom 时,我收到一个异常,指出core项目中缺少依赖项:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-ear-plugin:2.8:generate-application-xml (default-generate-application-xml) on project theear: Artifact[ejb:com.myapp:core] is not a dependency of the project. -> [Help 1]

theear is setup like so:

theear设置如下:

<project ...>
    ...

    <artifactId>theear</artifactId>
    <packaging>ear</packaging>

    <dependencies>
        <dependency>
            <groupId>com.myapp</groupId>
            <artifactId>web</artifactId>
            <version>${application.web.version}</version>
            <type>war</type>
            <scope>runtime</scope>
        </dependency>

        <!-- myapp projects -->
        <dependency>
            <groupId>com.myapp</groupId>
            <artifactId>core</artifactId>
        </dependency>

        ...
    </dependencies>

    <build>
        <finalName>theear</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                    <modules>
                        <webModule>
                            <groupId>com.myapp</groupId>
                            <artifactId>web</artifactId>
                            <contextRoot>/web</contextRoot>
                            <bundleFileName>web.war</bundleFileName>
                        </webModule>
                        <ejbModule>
                            <groupId>com.myapp</groupId>
                            <artifactId>core</artifactId>
                            <bundleFileName>core.jar</bundleFileName>
                        </ejbModule>
                    </modules>
                    <defaultLibBundleDir>lib/</defaultLibBundleDir>
                    <skinnyWars>true</skinnyWars>
                </configuration>
            </plugin>
            ...
        </plugins>
    </build>
</project>

And the core project like so:

核心项目是这样的:

<project ...>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>core</artifactId>
    <version>1.0.0.Pre-Alpha</version>
    <packaging>ejb</packaging>

    <dependencies>
        ...
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <ejbVersion>3.1</ejbVersion>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

As you can see the ear clearly lists the core module as a dependency

如您所见,耳朵清楚地将核心模块列为依赖项

NOTE:the version is missing as this pom declares an aggregate pom as it's parent with the corresponding dependencyManagement tags.

注意:版本丢失,因为这个 pom 声明了一个聚合 pom 作为它的父级,具有相应的 dependencyManagement 标签。

Any idea what may be the cause of this please?

知道这可能是什么原因吗?

采纳答案by coderatchet

I came across thiswebsite, and the problem was that I did not include the <type>ejb</type>element when listing the core dependency.

我遇到了这个网站,问题是我<type>ejb</type>在列出核心依赖项时没有包含该元素。

the full dependency should look like this:

完整的依赖应该是这样的:

    <dependency>
        <groupId>com.myapp</groupId>
        <artifactId>core</artifactId>
        <version>1.0.0.Pre-Alpha</version>
        <type>ejb</type>
    </dependency>

I don't know why but maven complains about not having the version when you specify the type as ejb.

我不知道为什么,但是当您将类型指定为 ejb 时,maven 会抱怨没有版本。

回答by Justo Disla

Maven fails to build the Application.xml when adding an EJB module as dependency to an EAR application. The reason is that the dependency must be of type ejb. That happens when manually adding an EJB Module to an EAR app dependencies. It also happens if adding a WAR module to an EAR manually. war should be specified in the POM for each dependency.

将 EJB 模块作为依赖项添加到 EAR 应用程序时,Maven 无法构建 Application.xml。原因是依赖项必须是 ejb 类型。将 EJB 模块手动添加到 EAR 应用程序依赖项时会发生这种情况。如果手动将 WAR 模块添加到 EAR,也会发生这种情况。应该在 POM 中为每个依赖项指定 war。