2014-02-22 164 views
1

我試圖部署一個Web項目,它在其WEB-INF/lib中有一個EJB jar文件。這個EJB在其構建路徑中配置了對log4j(jar)的引用。當我部署打包帶在WebSphere Application Server 8.5.5 Web項目.ear文件,並啓動內部的servlet中,我得到這個錯誤:如何在EJB jar文件中包含jar依賴關係?

我查了日誌,似乎參照「沒有找到「log4j.jar」。

[22/02/14 1:41:42:402 COT] 0000007c InjectionBind E CWNEN0030E: The @EJB factory encountered a problem getting the object instance pe.com.projectavalon.Servlet.ServletPrueba/prueba binding object. The exception message was: The EJB reference in the SampleWeb.war module of the SampleEAR application could not be resolved; nested exception is: com.ibm.ejs.container.ContainerEJBException: Unable to initialize deferred EJB.; nested exception is: com.ibm.ejs.container.ContainerException: Failed to start the Test component in the SampleWeb.war module of the SampleEAR application. : An operation in the enterprise bean constructor failed. It is recommended that component initialization logic be placed in a PostConstruct method instead of the bean class no-arg constructor.; nested exception is: 
    java.lang.NoClassDefFoundError: org/apache/log4j/Logger 
[22/02/14 1:41:42:404 COT] 0000007c webapp  E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[ServletPrueba]: com.ibm.wsspi.injectionengine.InjectionException: Unable to obtain an instance for pe.com.projectavalon.Servlet.ServletPrueba/prueba: javax.ejb.EJBException: The EJB reference in the SampleWeb.war module of the SampleEAR application could not be resolved; nested exception is: com.ibm.ejs.container.ContainerEJBException: Unable to initialize deferred EJB.; nested exception is: com.ibm.ejs.container.ContainerException: Failed to start the Test component in the SampleWeb.war module of the SampleEAR application. : An operation in the enterprise bean constructor failed. It is recommended that component initialization logic be placed in a PostConstruct method instead of the bean class no-arg constructor.; nested exception is: 
    java.lang.NoClassDefFoundError: org/apache/log4j/Logger 
    at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1123) 
    at com.ibm.ws.ejb.injection.processor.EJBInjectionBinding.getInjectionObject(EJBInjectionBinding.java:1101) 
    at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectableObject(InjectionBinding.java:1032) 
    at com.ibm.wsspi.injectionengine.InjectionTarget.inject(InjectionTarget.java:125) 
    at com.ibm.ws.injectionengine.AbstractInjectionEngine.inject(AbstractInjectionEngine.java:1065) 
    at com.ibm.ws.webcontainer.annotation.WASAnnotationHelper.inject(WASAnnotationHelper.java:380) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.createTarget(ServletWrapperImpl.java:261) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper$1.run(ServletWrapper.java:1486) 
    at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.loadServlet(ServletWrapper.java:1472) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:620) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:458) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1032) 
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87) 
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:909) 
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662) 
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:459) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:526) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:312) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:283) 
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214) 
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113) 
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175) 
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) 
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) 
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) 
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) 
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) 
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) 
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1862) 

當我檢查ejb jar文件時,發現log4j不存在。我如何在EJB Jar文件中包含log4j的jar包?

回答

1

如果在WEB-INF\lib目錄下有log4j.jar文件會更好。然後,它可以被Web應用程序和ejb應用程序代碼庫使用。爲此,請確保在您的ejb jar文件中有META-INF/MANIFEST.MF文件指定Class-Path條目下的log4j jar文件路徑。請記住,路徑必須相對於您的ejb jar文件。

例如,在下面你可以在MANIFEST.MF的Class-Path進入指定爲lib/log4j.jar

WAR 
| 
-- WEB-INF 
    | 
    -- web.xml 
    | 
    -- classes 
    | 
    -- lib 
     | 
     -- ejb jar 
     |  | 
     |  |-- META-INF 
     |    | 
     |    -- MANIFEST.MF 
     | 
     | 
     | 
     |-- log4j.jar 

結構(格式是不是很大,因爲它是手工鍵入)

+0

完美的作品。我有一些東西需要調整,但是作爲servlet的調用,效果很好。謝謝。並格式化它很清楚,不用擔心= D – Xanathos

+0

不客氣:-) – IndoKnight

2

您是否創建過或是根據META-INF/MANIFEST.MF生成的?

在Manifest中,您可以指定應該裝入哪些罐子。爲了這個工作,你應該把瓶子直接放在耳朵裏。

這裏有一個tutorial

-1

設置一個在應用程序服務器(ENVIRONMENT> SHARED LIBRARIES)中共享lib並將所有jar放入該路徑。 您需要在Web項目中的Manifest.mf中提及您的罐子。清單文件的路徑是WebContent> META-INF。