无法部署ear文件

时间:2012-01-05 21:20:05

标签: java-ee netbeans maven

我正在尝试将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,我确信这是一些我不知道的简单。

感谢。

1 个答案:

答案 0 :(得分:0)

无法查看您的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就不会在其存储库中查找您的jar。以下是描述的可能性:

  

范围:   此元素引用手头任务的类路径(编译和运行时,测试,等等)以及如何限制依赖项的传递性。有五个范围&gt;可用:编译,提供,运行时,测试,系统。

     

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

     

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

     

运行时 - 此范围表示编译不需要依赖关系,但是> gt执行。它位于运行时和测试类路径中,但不是编译类路径。

     

test - 此范围表示正常使用&gt;应用程序不需要依赖关系,并且仅适用于测试编译和执行阶段。

     

system - 此范围与提供的类似,只是您必须提供明确包含它的JAR。该工件始终可用,并且未在&gt;存储库中查找。

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