【问题标题】:Trouble deploying ear file部署 ear 文件时遇到问题
【发布时间】:2023-03-18 06:45:01
【问题描述】:

我正在尝试将 EAR 文件部署到应用程序服务器。该项目使用 NetBeans 7 中的 Maven 3 构建。

当我尝试部署 Glassfish 和 Websphere CE 时,告诉我某些类无法找到,即使它们已打包在 EAR 文件中。应用服务器可以看到包中的其他类,但不是全部。

问题可能是什么?我整天都在努力解决这个问题。我查看了 Maven POM 文件,并且一直在阅读有关部署描述符的信息,但似乎没有进行中。

我得到的错误是 严重:找不到类 [className]。加载 [className] 时出错

这是项目的主要 pom 文件:

<modelVersion>4.0.0</modelVersion>
<parent>
    <artifactId>SeaMarNetting</artifactId>
    <groupId>com.manageinc.seamar</groupId>
    <version>1.0RC1</version>
</parent>
<groupId>${project.parent.groupId}</groupId>
<artifactId>SeaMarNetting-ear</artifactId>
<packaging>ear</packaging>
<version>${project.parent.version}</version>
<name>SeaMarNetting-ear JEE5 Assembly</name>
<url>http://maven.apache.org</url>
<dependencies>
    <dependency>
        <groupId>${project.parent.groupId}</groupId>
        <artifactId>SeaMarNetting-project-deps</artifactId>
        <version>${project.parent.version}</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>${project.parent.groupId}</groupId>
        <artifactId>SeaMarNetting-ejb</artifactId>
        <version>${project.parent.version}</version>
        <type>ejb</type>
    </dependency>
    <dependency>
        <groupId>${project.parent.groupId}</groupId>
        <artifactId>SeaMarNetting-jpa</artifactId>
        <version>${project.parent.version}</version>            
    </dependency>
    <dependency>
        <groupId>${project.parent.groupId}</groupId>
        <artifactId>SeaMarNetting-web</artifactId>
        <version>${project.parent.version}</version>
        <type>war</type>
    </dependency>
    <dependency>
        <groupId>com.manageinc.seamar</groupId>
        <artifactId>SeaMarNetting-web</artifactId>
        <version>1.0RC1</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>${source.version}</source>
                <target>${compile.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.4.2</version>
            <configuration>
                <version>5</version>
                <displayName>SeaMarNetting</displayName>
                <modules>                        
                    <jarModule>
                        <groupId>${project.parent.groupId}</groupId>
                        <artifactId>SeaMarNetting-jpa</artifactId>
                    </jarModule>
                    <ejbModule>
                        <groupId>${project.parent.groupId}</groupId>
                        <artifactId>SeaMarNetting-ejb</artifactId>
                    </ejbModule>
                    <webModule>
                        <groupId>${project.parent.groupId}</groupId>
                        <artifactId>SeaMarNetting-web</artifactId>
                        <contextRoot>/nets</contextRoot>
                    </webModule>
                </modules>
            </configuration>
        </plugin>
    </plugins>
</build>

我尝试按照建议更改范围,但收到相同的错误消息。我刚开始使用 Maven,我确信这很简单,我不知道。

谢谢。

【问题讨论】:

    标签: jakarta-ee netbeans maven


    【解决方案1】:

    如果无法查看您的 POM 文件,我最好的猜测是您没有正确定义依赖项。 Apache 的 POM 参考地址:http://maven.apache.org/pom.html#The_Basics 显示:

    <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.0</version>
      <type>jar</type>
      <scope>test</scope>
      <optional>true</optional>
    </dependency>
    ...
    

    我认为您需要关注“范围”属性,您可以将其列为“提供”或“系统”。这样 maven 就不会在其存储库中查找您的 jars。以下是带有描述的可能性:

    范围: 该元素指的是手头任务的类路径(编译和运行时、测试等)以及如何限制依赖项的传递性。有五个范围 >available:compile、provided、runtime、test、system。

    compile - 这是默认范围,如果未指定则使用。编译依赖项在所有类路径中都可用。此外,这些依赖项会传播到相关的 >projects。

    provided - 这很像 compile,但表示您希望 JDK 或容器在运行时 >provided 它。它仅在编译和测试类路径中可用,并且>不可传递。

    runtime - 此范围表示编译不需要依赖项,但>执行。它在运行时和测试类路径中,但不在编译类路径中。

    test - 此范围表示该依赖项对于应用程序的正常使用不是必需的,仅适用于测试编译和执行阶段。

    system - 这个范围类似于提供的,除了你必须提供显式包含它的 JAR。工件始终可用,不会在 >repository 中查找。

    记住为每个与存储库的 groupId 对应的依赖项包含一个 groupId 也很重要。我发现即使我的文件保存在本地,它们仍然需要一个 groupId - 即使范围是“提供的”。

    【讨论】:

    • 感谢您回复 TedPrz。问题是 glassfish 看不到持久层的罐子。耳朵由一个 jar 组成,每个 jar 用于 ejb、web 和 jpa。我可以在 Websphere Express 上部署和运行该应用程序,但不能在 glassfish 或 Websphere CE 上。有问题的罐子在 EAR 内。
    • 您确定耳朵包装正确吗?有什么方法可以发布部分 .xml 文件?
    • 不,我不确定 EAR 是否正确打包。我开始使用 Maven 构建的现有项目。这是我第一次使用 Maven。该项目在 NetBeans 中构建良好并在生产服务器上运行。我正在尝试设置开发服务器。
    • 您可能还想看看 maven 如何从父 pom 继承。您之前的项目中可能存在影响您当前项目的设置——尤其是当您将当前项目迁移到另一个不存在父 pom 的服务器时。可能有一些设置没有保留。祝你好运。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-03
    • 2012-03-03
    • 2014-12-08
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    相关资源
    最近更新 更多