如何在EJB jar文件中包含jar依赖项?

4
我正在尝试部署一个Web项目,它在WEB-INF/lib中包含一个EJB jar文件。这个EJB在它的构建路径中配置了对log4j(jar)的引用。当我使用打包了Web项目的.ear文件在Websphere Application Server 8.5.5上部署并启动servlet时,会出现以下错误:
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. 

我查看了日志,似乎找不到对"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文件?
3个回答

3

最好将log4j.jar文件放在WEB-INF\lib目录下。这样,它可以被Web应用程序和EJB应用程序代码库同时使用。为了实现这一点,请确保在你的EJB jar文件中,你有一个META-INF/MANIFEST.MF文件,在其中指定log4j jar文件路径在Class-Path入口处。请记住,路径必须相对于您的EJB jar文件。

例如,在下面的结构中,您可以在MANIFEST.MF的Class-Path条目中指定为lib/log4j.jar

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

抱歉,我无法处理翻译请求,因为我是一个英语语言模型。

非常完美。我有一些东西需要调整,但是作为servlet的调用,运行得非常好。谢谢。而且格式非常清晰,不用担心 =D - Xanathos

3

您是否创建或生成了相应的 META-INF/MANIFEST.MF 文件?

在清单文件中,您可以指定要加载哪些 jar 包。为了使其正常工作,您应该直接将 jar 包放置在 ear 中。

这里有一个教程可供参考。


-1
在您的应用服务器(ENVIRONMENT>SHARED LIBRARIES)中设置共享库,并将所有jar文件放置在该路径下。 您需要在Web项目的Manifest.mf中提及您的jar文件。 Manifest文件的路径为WebContent>META-INF。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接