Websphere ejb2.0、log4j和EAR项目配置

Websphere ejb2.0、log4j和EAR项目配置,websphere,ejb-2.x,Websphere,Ejb 2.x,我在EJB2.0上又发布了一个问题。我想我前面的问题不会得到任何答案,因为EJB2.0是一种非常过时的技术,没有人想再使用它了。但是我的问题得到了回答,我又一次碰碰运气了 我创建了一个简单的EJB2.x实体bean。我的实体bean使用另一个类(UniqueIdGenerator)为持久主键字段生成主键的值。UniqueIdGenerator使用log4j和JDBC连接,所以我为EJB项目配置了适当的构建路径引用 为EJB项目的buildpath添加了以下JAR log4j-1.2.16.jar

我在EJB2.0上又发布了一个问题。我想我前面的问题不会得到任何答案,因为EJB2.0是一种非常过时的技术,没有人想再使用它了。但是我的问题得到了回答,我又一次碰碰运气了

我创建了一个简单的EJB2.x实体bean。我的实体bean使用另一个类(UniqueIdGenerator)为持久主键字段生成主键的值。UniqueIdGenerator使用log4j和JDBC连接,所以我为EJB项目配置了适当的构建路径引用

为EJB项目的buildpath添加了以下JAR log4j-1.2.16.jar db2jcc.jar db2jcc_license_cu.jar

然后,我将持久字段映射到数据库表字段。使用RSA中的“准备部署”选项生成的代码(在WAS上部署)

创建EAR项目并使用项目引用选项将EJB项目(HMS)添加到EAR项目中

我没有设置任何其他路径/类路径

启动WAS,在WAS上部署EAR,并启动UniversalTestClient来测试实体bean。我尝试使用远程接口创建我的第一个bean,输入字段的值,然后单击UniversalTestClient上的submit。在服务器端,它调用了实体bean的ejbCreate(),但在加载UniqueIdGenerator类时失败,错误为NoClassDefFoundError

这是堆栈跟踪

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    com.ibm.ejs.container.CreateFailureException: ; nested exception is: 
    java.lang.NoClassDefFoundError: org.apache.log4j.LogManager
    at com.ibm.CORBA.iiop.UtilDelegateImpl.mapSystemException(UtilDelegateImpl.java:235)
    at com.ibm.CORBA.iiop.UtilDelegateImpl.wrapException(UtilDelegateImpl.java:743)
    at javax.rmi.CORBA.Util.wrapException(Util.java:296)
    at ejbs._EJSRemoteCMPAddressHome_824957aa_Stub.create(_EJSRemoteCMPAddressHome_824957aa_Stub.java:258)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at com.ibm.etools.utc.model.ReflectionMethodModel.invoke(ReflectionMethodModel.java:65)
    at com.ibm.etools.utc.servlet.InvokeServlet.invoke(InvokeServlet.java:113)
    at com.ibm.etools.utc.servlet.InvokeServlet.doPost(InvokeServlet.java:374)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1657)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    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:1604)
Caused by: com.ibm.ejs.container.CreateFailureException: ; nested exception is: 
    java.lang.NoClassDefFoundError: org.apache.log4j.LogManager
    at ejbs.EJSCMPAddressHomeBean_824957aa.create(EJSCMPAddressHomeBean_824957aa.java:47)
    at ejbs.EJSRemoteCMPAddressHome_824957aa.create(EJSRemoteCMPAddressHome_824957aa.java:28)
    at ejbs._EJSRemoteCMPAddressHome_824957aa_Stub.create(_EJSRemoteCMPAddressHome_824957aa_Stub.java:251)
    ... 29 more
Caused by: java.lang.NoClassDefFoundError: org.apache.log4j.LogManager
    at utils.UniqueLongIdGenerator.(UniqueLongIdGenerator.java:40)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    at utils.UniqueIdGenerator.(UniqueIdGenerator.java:28)
    at utils.UniqueIdGenerator.(UniqueIdGenerator.java:24)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    at ejbs.AddressBean.ejbCreate(AddressBean.java:46)
    at ejbs.ConcreteAddress_824957aa.ejbCreate(ConcreteAddress_824957aa.java:122)
    at ejbs.EJSCMPAddressHomeBean_824957aa.create(EJSCMPAddressHomeBean_824957aa.java:33)
    ... 31 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.LogManager
    at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
    at com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:191)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:660)
    at com.ibm.ws.bootstrap.ExtClassLoader.loadClass(ExtClassLoader.java:111)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:626)
    at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:62)
    at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:58)
    at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:509)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:626)
    ... 41 more

我在配置中遗漏了什么。我是否需要在EAR项目的某个地方添加所有jar文件。在EJB项目的构建路径中设置它们还不够吗?

我在以下链接中找到了答案

Developerworks文章


您需要将第三方JAR导入EAR项目,然后在EJB项目MANIFEST.MF文件中设置JAR依赖项。将外部JAR导入EAR项目后,它们将在explorer for MANIFEST中可用。MF

将JAR添加到构建路径只会影响编译。你需要把罐子放在实际的耳朵里;如果您导出EAR,而JAR未包含在内,则项目配置不正确。感谢bkail,我按照同样的思路进行了更多调查,发现我需要在EAR中添加/链接第三方JAR,并通过将其添加到manifest.mf文件将其包含在类路径中。如果您发现注释有用,您可以将鼠标悬停在注释的左侧,然后单击向上箭头图标。