ejb2.0,log4j和EAR项目配置

时间:2013-06-05 06:58:09

标签: websphere ejb-2.x

我在EJB2.0上发布了另外一个问题。我认为我之前的问题不会得到任何答案,因为EJB2.0已经是过时的技术,没有人愿意继续研究它。但是我的first question得到了回答,我又一次试着运气了。

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

在EJB项目的构建路径中添加了以下JARS log4j的-1.2.16.jar 的db2jcc.jar 为db2jcc_license_cu.jar

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

创建EAR项目并使用Project References选项将EJB项目(HMS)添加到EAR项目。

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

启动WAS,在WAS上部署EAR并启动Universal Test Client以测试实体bean。使用远程接口我试图创建我的第一个bean,我输入了字段的值,然后在Universal test client上点击提交。在服务器端,它调用实体bean的ejbCreate()但在加载带有错误NoClassDefFoundError的UniqueIdGenerator类时失败

这是堆栈跟踪

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项目的构建路径中设置它们是不够的?

1 个答案:

答案 0 :(得分:1)

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

How to include external jar in ejb-jar

Developerworks文章 http://www.ibm.com/developerworks/rational/library/07/1211_schrag/index.html

您需要将第三方jar导入EAR项目,然后在EJB项目MANIFEST.MF文件中设置JAR依赖项。将外部罐子导入EAR项目后,它们将在资源管理器中用于MANIFEST.MF