Question

I'm trying to deploy a web project that has in its WEB-INF/lib a EJB jar file. This EJB has configure in its build path a reference to log4j (the jar). When I deploy the .ear file with the web project packaged in Websphere Application Server 8.5.5, and start the servlet inside, i get this error:

Error 500: javax.servlet.ServletException: SRVE0319E: For the [ServletPrueba] servlet, pe.com.projectavalon.Servlet.ServletPrueba servlet class was found, but a resource injection failure has occurred. 

I checked the logs, seems that the reference to the "log4j.jar" are not being found.

[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)

When I checked the ejb jar file, I found that the log4j isn't there. How can I include the jar of log4j inside the EJB Jar file?

Was it helpful?

Solution 2

It is better if you have log4j.jar file under WEB-INF\lib directory. Then, it can be used by both web application and ejb application code base. To do this, make sure in your ejb jar file you have META-INF/MANIFEST.MF file specify the log4j jar file path under Class-Path entry. Bear in mind, the path has to be relative to your ejb jar file.

For example, in the structure below you can specify in the Class-Path entry of MANIFEST.MF as lib/log4j.jar

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

(formatting is not that great as it is hand-typed)

OTHER TIPS

Have you created or was the according META-INF/MANIFEST.MF generated?

Within the Manifest you can specify which jars should be loaded as well. For this to work you should place the jars directly in the ear.

There is a tutorial for this.

Setup a shared lib in your application server(ENVIRONMENT >SHARED LIBRARIES) and put all your jars in that path. You need to mention your jars in Manifest.mf in your web project. Path for manifest file is WebContent>META-INF.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top