2012-02-05 194 views
2

我採用完全相同的Web應用程序,並將其部署爲WAR,沒有任何問題。但是,部署爲EAR的相同應用程序失敗。相同的文件,只是不同的部署。首先看WAR:JBoss AS 7錯誤:WAR部署成功,EAR部署失敗

Webapp.war 
. 
|-- error.xhtml 
|-- index.xhtml 
|-- language.xhtml 
|-- login.xhtml 
|-- META-INF 
|-- register.xhtml 
|-- resources 
| |-- css 
| | `-- layout.css 
| |-- images 
| | `-- logo.png 
| `-- javascript 
|  `-- detectScreenSize.js 
|-- sendMail.xhtml 
|-- templates 
| `-- masterLayout.xhtml 
`-- WEB-INF 
    |-- beans.xml 
    |-- classes 
    | |-- ApplicationResources_es.properties 
    | |-- ApplicationResources.properties 
    | |-- com 
    | | `-- webapp 
    | |  |-- controller 
    | |  | |-- auth 
    | |  | | |-- ClientInfo.class 
    | |  | | |-- LoginModule.class 
    | |  | | |-- RBAC.class 
    | |  | | |-- SimpleGroup.class 
    | |  | | `-- SimplePrincipal.class 
    | |  | |-- LocaleManager.class 
    | |  | |-- SendMailBean.class 
    | |  | |-- UserRegistration.class 
    | |  | `-- UserRemoval.class 
    | |  |-- data 
    | |  | `-- UserListProducer.class 
    | |  |-- exception 
    | |  | |-- ViewExpiredExceptionExceptionHandler.class 
    | |  | `-- ViewExpiredExceptionExceptionHandlerFactory.class 
    | |  |-- model 
    | |  | |-- Entity.class 
    | |  | |-- LoginHistory.class 
    | |  | |-- Role.class 
    | |  | |-- User.class 
    | |  | `-- UserRole.class 
    | |  `-- util 
    | |   |-- Resources.class 
    | |   |-- TimestampAdapter.class 
    | |   `-- Util.class 
    | |-- META-INF 
    | | |-- beans.xml 
    | | `-- persistence.xml 
    | `-- ValidationMessages.properties 
    |-- faces-config.xml 
    |-- jboss-web.xml 
    |-- lib 
    | |-- cssparser-0.9.5.jar 
    | |-- guava-r08.jar 
    | |-- richfaces-components-api-4.0.0.Final.jar 
    | |-- richfaces-components-ui-4.0.0.Final.jar 
    | |-- richfaces-core-api-4.0.0.Final.jar 
    | |-- richfaces-core-impl-4.0.0.Final.jar 
    | `-- sac-1.3.jar 
    |-- navigation.xml 
    `-- web.xml 

現在,這裏是EAR。相同的文件(除了現在它有application.xml),只是不同的結構。

Webapp.ear 
. 
|-- META-INF 
| |-- application.xml 
| |-- MANIFEST.MF 
| `-- maven 
|  `-- com.webapp 
|   `-- Webapp-ear 
|    |-- pom.properties 
|    `-- pom.xml 
|-- Webapp-ejb-1.0-SNAPSHOT.jar 
`-- Webapp-web-1.0-SNAPSHOT.war 

這裏的EJB JAR文件:

Webapp-ejb-1.0-SNAPSHOT.jar 
. 
|-- ApplicationResources_es.properties 
|-- ApplicationResources.properties 
|-- com 
| `-- webapp 
|  |-- controller 
|  | |-- auth 
|  | | |-- ClientInfo.class 
|  | | |-- LoginModule.class 
|  | | |-- RBAC.class 
|  | | |-- SimpleGroup.class 
|  | | `-- SimplePrincipal.class 
|  | |-- LocaleManager.class 
|  | |-- SendMailBean.class 
|  | |-- UserRegistration.class 
|  | `-- UserRemoval.class 
|  |-- data 
|  | `-- UserListProducer.class 
|  |-- exception 
|  | |-- ViewExpiredExceptionExceptionHandler.class 
|  | `-- ViewExpiredExceptionExceptionHandlerFactory.class 
|  |-- model 
|  | |-- Entity.class 
|  | |-- LoginHistory.class 
|  | |-- Role.class 
|  | |-- User.class 
|  | `-- UserRole.class 
|  `-- util 
|   |-- Resources.class 
|   |-- TimestampAdapter.class 
|   `-- Util.class 
|-- META-INF 
| |-- beans.xml 
| |-- MANIFEST.MF 
| |-- maven 
| | `-- com.webapp 
| |  `-- Webapp-ejb 
| |   |-- pom.properties 
| |   `-- pom.xml 
| `-- persistence.xml 
`-- ValidationMessages.properties 

這裏的WAR文件:

Webapp-web-1.0-SNAPSHOT.war 
. 
|-- error.xhtml 
|-- index.xhtml 
|-- language.xhtml 
|-- login.xhtml 
|-- META-INF 
| |-- MANIFEST.MF 
| `-- maven 
|  `-- com.webapp 
|   `-- Webapp-web 
|    |-- pom.properties 
|    `-- pom.xml 
|-- register.xhtml 
|-- resources 
| |-- css 
| | `-- layout.css 
| |-- images 
| | `-- logo.png 
| `-- javascript 
|  `-- detectScreenSize.js 
|-- sendMail.xhtml 
|-- templates 
| `-- masterLayout.xhtml 
`-- WEB-INF 
    |-- beans.xml 
    |-- faces-config.xml 
    |-- jboss-web.xml 
    |-- lib 
    | |-- cssparser-0.9.5.jar 
    | |-- guava-r08.jar 
    | |-- richfaces-components-api-4.0.0.Final.jar 
    | |-- richfaces-components-ui-4.0.0.Final.jar 
    | |-- richfaces-core-api-4.0.0.Final.jar 
    | |-- richfaces-core-impl-4.0.0.Final.jar 
    | `-- sac-1.3.jar 
    |-- navigation.xml 

    `-- web.xml 

這裏是EAR部署的application.xml:

​​

WAR部署沒有錯誤,但EAR

17:41:02,059 WARN [org.jboss.modules] (MSC service thread 1-2) Failed to define class com.webapp.exception.ViewExpiredExceptionExceptionHandler in Module "deployment.Webapp.ear.Webapp-ejb-1.0-SNAPSHOT.jar:main" from Service Module Loader: java.lang.LinkageError: Failed to link com/webapp/exception/ViewExpiredExceptionExceptionHandler (Module "deployment.Webapp.ear.Webapp-ejb-1.0-SNAPSHOT.jar:main" from Service Module Loader) 

    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:396) 

    at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:243) 

    at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73) 

    at org.jboss.modules.Module.loadModuleClass(Module.java:505) 

    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182) 

    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) 

    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) 

    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) 

    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) 

    at org.jboss.as.jpa.hibernate4.HibernateAnnotationScanner.getPackagesInJar(HibernateAnnotationScanner.java:92) 

    at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:490) [hibernate-entitymanager-4.0.0.Final.jar:4.0.0.Final] 

    at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:852) [hibernate-entitymanager-4.0.0.Final.jar:4.0.0.Final] 

    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:597) [hibernate-entitymanager-4.0.0.Final.jar:4.0.0.Final] 

    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72) [hibernate-entitymanager-4.0.0.Final.jar:4.0.0.Final] 

    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:149) [jboss-as-jpa-7.1.0.CR1b.jar:7.1.0.CR1b] 

    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:79) [jboss-as-jpa-7.1.0.CR1b.jar:7.1.0.CR1b] 

    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) 

    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) 

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [:1.7.0_02] 

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [:1.7.0_02] 

    at java.lang.Thread.run(Thread.java:722) [:1.7.0_02] 

Caused by: java.lang.NoClassDefFoundError: javax/faces/context/ExceptionHandlerWrapper 

    at java.lang.ClassLoader.defineClass1(Native Method) [:1.7.0_02] 

    at java.lang.ClassLoader.defineClass(ClassLoader.java:791) [:1.7.0_02] 

    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) [:1.7.0_02] 

    at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:327) 

    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:391) 

    ... 20 more 

Caused by: java.lang.ClassNotFoundException: javax.faces.context.ExceptionHandlerWrapper from [Module "deployment.Webapp.ear.Webapp-ejb-1.0-SNAPSHOT.jar:main" from Service Module Loader] 

    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) 

    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) 

    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) 

    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) 

    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) 

    ... 25 more 

17:41:02,143 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.persistenceunit."Webapp.ear/Webapp-ejb-1.0-SNAPSHOT.jar#PostgresPersistenceUnit": org.jboss.msc.service.StartException in service jboss.persistenceunit."Webapp.ear/Webapp-ejb-1.0-SNAPSHOT.jar#PostgresPersistenceUnit": Failed to start service 

    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1780) [jboss-msc-1.0.1.GA.jar:1.0.1.GA] 

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [:1.7.0_02] 

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [:1.7.0_02] 

    at java.lang.Thread.run(Thread.java:722) [:1.7.0_02] 

Caused by: java.lang.RuntimeException: error trying to scan <jar-file>: vfs:/content/Webapp.ear/Webapp-ejb-1.0-SNAPSHOT.jar/ 

    at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:855) 

    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:597) 

    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72) 

    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:149) 

    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:79) 

    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA] 

    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA] 

    ... 3 more 

Caused by: java.lang.RuntimeException: JBAS011431: Could not load entity class 'com.webapp.exception.ViewExpiredExceptionExceptionHandler' with PersistenceUnitInfo.getNewTempClassLoader() 

    at org.jboss.as.jpa.hibernate4.HibernateAnnotationScanner.getPackagesInJar(HibernateAnnotationScanner.java:96) 

    at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:490) 

    at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:852) 

    ... 9 more 

Caused by: java.lang.ClassNotFoundException: com.webapp.exception.ViewExpiredExceptionExceptionHandler from [Module "deployment.Webapp.ear.Webapp-ejb-1.0-SNAPSHOT.jar:main" from Service Module Loader] 

    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) 

    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) 

    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) 

    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) 

    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) 

    at org.jboss.as.jpa.hibernate4.HibernateAnnotationScanner.getPackagesInJar(HibernateAnnotationScanner.java:92) 

    ... 11 more 

很奇怪的是,錯誤是::

Caused by: java.lang.RuntimeException: JBAS011431: Could not load entity class 'com.webapp.exception.ViewExpiredExceptionExceptionHandler' with PersistenceUnitInfo.getNewTempClassLoader()

ViewExpiredExceptionHandler不是一個實體,那麼,爲什麼PersistenceUnitInfo儘量加載它未能如下部署?

我使用了"org.jboss.spec.archetypes:jboss-javaee6-ear-webapp" maven原型來生成EAR項目的模板和poms,我使用maven jboss-as:deploy插件來部署EAR。我正在使用jboss-as-7.1.0.CR1b

我的web.xml是Servlet規範3.0:

<web-app 
    version="3.0" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 

什麼我沒有得到嗎?請幫忙。

回答

2

首先你的EJB bean不應該依賴於JSF庫。 JSF是爲查看部分應用程序而設計的框架(html + backing beans)。 EJB模塊應該在沒有關於JSF的知識的情況下運行。

如果您確實需要從EJB方法引用JSF,則必須明確通知容器(JBoss 7.1。)該模塊依賴於JSF模塊。你可以在這裏找到細節: https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7

+1

類加載文檔爲7.1可在https:// docs上找到。 jboss.org/author/display/AS71/Class+Loading+in+AS7 – ctomc 2013-07-02 10:15:47

2

當使用EAR部署時,EJB應位於EAR的/lib目錄中,或者您需要添加<ear-subdeployments-isolated>false</ear-subdeployments-isolated>以使EE子系統識別EJB JAR。

另一種選擇是將Dependencies: Webapp-ejb-1.0-SNAPSHOT添加到WAR中的MANIFEST.MF。

您可以從以下文檔https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7中獲得有關使用EAR進行類加載的更多信息。

+0

我讀了你指出的信息,這是非常有幫助的。我使用jboss'maven archetype「org.jboss.spec.archetypes:jboss-javaee6-ear-webapp」來生成項目,它沒有包含依賴項或類路徑清單條目,儘管它確實有一個ejb - 見[here ](HTTP://計算器。com/a/8776267/984932)查看原型生成的項目 - 可能是因爲JBoss'默認爲false。項目中的ejb有一個可以從facelet視圖訪問的生產者方法,並且在沒有任何JBoss配置修改的情況下工作正常。 – 2012-02-06 20:25:21

+0

但是我遇到的問題與EAR中的模塊無關,無法訪問EAR中的其他類。爲了調試,我從應用程序中刪除了ViewExpiredExceptionHandler,並發現底層問題是EJB模塊中的類不能引用faces.context。*包中的任何對象,否則會引發ClassNotFoundException。當我刪除對FacesContext,ActionEvent等對象的引用時,應用程序無錯地部署。這應該是JBoss AS7的一個bug。有關於它的討論[這裏](https://community.jboss.org/thread/194780)。 – 2012-02-06 20:34:36

+0

好的,在論壇上準備好了,它確實有一些需要添加到EJB部署中的依賴關係。它看起來像你在那裏得到了更好的幫助,所以我將它留給論壇:-) – 2012-02-07 17:09:46