2012-01-05 134 views
1

我試圖將EAR文件部署到應用程序服務器。該項目使用NetBeans 7中的Maven 3構建。部署ear文件時出現問題

當我嘗試部署Glassfish和Websphere CE時,告訴我某些類即使它們打包在EAR文件中也無法找到。應用程序服務器可以查看包中的其他類,但不是全部。

問題是什麼?我一直在努力解決這一整天。我查看了Maven POM文件,並且一直在閱讀有關部署描述符的內容,但我似乎並未在進行中。

我得到的錯誤是 SEVERE:Class [className] not found。加載時出錯[類名]

下面是該項目的主要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,我確信這是簡單的,我不知道。

謝謝。

回答

0

不能看到你的POM文件,我最好的猜測是你沒有正確定義你的依賴關係。 http://maven.apache.org/pom.html#The_Basics顯示:在Apache的POM參考

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

我認爲你需要把重點放在「範圍」屬性,在這裏你可以將其列爲無論是「提供」或「系統」。這樣,maven不會在其存儲庫中查找您的罐子。以下是可能的瓦特/描述:

範圍: 該元素指的是在手頭的任務的類路徑(編譯和運行時,測試,>等),以及如何限制依賴性的傳遞。有五個範圍可用:編譯,提供,運行時,測試,系統。

編譯 - 這是默認範圍,如果沒有指定,則使用。編譯依賴關係在所有類路徑中都可用。此外,這些依賴關係會傳播到依賴項目。

提供 - 這非常類似於編譯,但表示您希望JDK或容器在運行時提供它。它僅在編譯和測試類路徑中可用,並且不可傳遞。

運行時 - 此範圍指示編譯時不需要依賴項,但是要執行該依賴項。它在運行時和測試類路徑中,但不在編譯類路徑中。

測試 - 此範圍指示正常使用>應用程序時不需要依賴關係,並且僅適用於測試編譯和執行階段。

系統 - 該範圍與提供的範圍相似,只是必須明確提供包含它的JAR。該工件始終可用,並且不會在>存儲庫中查找。

記住爲每個與存儲庫的groupId對應的依賴項包含groupId也很重要。我發現即使我的文件保存在本地,他們仍然需要一個groupId - 即使範圍是'提供'。

+0

感謝您回覆TedPrz。問題是持久層的瓶子沒有被glassfish看到。耳朵由ejb,web和jpa中的每個jar組成。我可以在Websphere Express上部署和運行應用程序,但不能在glassfish和Websphere CE上運行。有問題的罐子在EAR裏面。 – user1054606 2012-01-09 22:53:46

+0

你確定耳朵包裝正確嗎?有什麼辦法可以發佈部分.xml文件嗎? – Ted 2012-01-10 12:13:48

+0

不,我不確定EAR是否正確打包。我開始使用Maven構建的現有項目。這是我第一次使用Maven。該項目在NetBeans中正常生成並在生產服務器上運行。我試圖建立一個開發服務器。 – user1054606 2012-01-10 16:39:09