Classloader problem with EJB

允我心安 提交于 2019-12-11 07:09:03

问题


I'm working on a project which includes persistence library (JPA 1.2), EJB 3 and Web presentation layer (JSF). I develop application using Eclipse and application is published on Websphere Application Server Community Edition (Geronimo 2.1.4) through eclipse plugin (but the same thing happens if I publish manually). When publishing to server I get the following error:

java.lang.NoClassDefFoundError: Could not fully load class: manager.administration.vehicles.VehicleTypeAdminBean
 due to:manager/vehicles/VehicleType
 in classLoader: 
org.apache.geronimo.kernel.classloader.TemporaryClassLoader@18878c7
    at org.apache.xbean.finder.ClassFinder.(ClassFinder.java:177)
    at org.apache.xbean.finder.ClassFinder.(ClassFinder.java:146)...

In web.xml I have reference to EJB:

<ejb-local-ref>
    <ejb-ref-name>ejb/VehicleTypeAdmin</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local>manager.administration.vehicles.VehicleTypeAdmin</local>
    <ejb-link>VehicleTypeAdminBean</ejb-link>
</ejb-local-ref>

EJB project has a reference to persistence project, and Web project has references to both projects. I don't get any compilation errors, so I suppose classes and references are correct.

I don't know if it is app server problem, but I ran previously application on the same server using same configuration parameters.

Does anybody have a clue what might be the problem?


回答1:


Looks almost like it couldn't find the class manager.vehicles.VehicleType when it was attempting to create/load the class manager.administration.vehicles.VehicleTypeAdminBean.

I've encountered similar problems before. When the class loader attempts to load the class it looks at the import statements (and other class usage declarations) and then attempts to load those classes and so on until it reaches the bottom of the chain (ie java.lang.Object). If it cannot find one class along the chain (in your case it looks like it cannot load VehicleType) then it will state that it cannot load the class at the top of the chain (in your case VehicleTypeAdminBean).

Is the VehicleType class in a different jar? If you have a web module and and EJB module do you have the jar containing the VehicleType class in the appropriate place(s). Sometimes with web projects you have to put the jars in the WebContent/WEB-INF/lib folder or it won't find them.

Are both of these projects deployed separately (ie. two ears? or one ear and one war?) or are they together (ie, one ear with jars and a war inside?). I'm assuming the second given you declared your EJB local?

The jars that you are dependent on also have to be declared in your MANIFEST.MF files in the projects that use it.

I'm kind of running on guesses since I do not know your project structure. Showing that would help quite a bit. But I'd still check on where VehicleType is located with regards to your EJB class. You might find it isn't where you think it is come packaging or runtime.




回答2:


Thanks @Chris for WebContent/WEB-INF/lib idea ! it works for me by following these steps :

1- Export my EJBs to a JAR (MyEJBs.jar) 2- I created another jar with your_installation_path/IBM/SDP/runtimes/your_version/binCreateEJBStrub.bat via CMD.exe, by executing this command :

createEJBStubs.bat <my_path>/MyEJBs.jar -newfile –quiet

3- A new jar will be automatically created in the same directory as MyEJBs.jar named MyEJBs_withStubs.jar

4- Put your new jar in WebContent/WEB-INF/lib

5- Call your EJBs by :

MyEJBRemote eJBRemote;
InitialContext ic = new InitialContext();
obj = ic.lookup("your_ejb_name_jndi");
eJBRemote = (MyEJBRemote ) PortableRemoteObject.narrow(obj,
MyEJBRemote.class);
eJBRemote = (MyEJBRemote ) obj;

Now you can call your EJBs from another EAR



来源:https://stackoverflow.com/questions/3461866/classloader-problem-with-ejb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!