开发者

Where to package Class file so that both Client apps and EJBs on Server have access?

I am new to the Java EE platform and I am building a simple JMS app. I created a class that is being sent in an ObjectMessage. My problem arose when both the client app creating the message and the MDB on the server needed access to the same class file(the class composed in the ObjectMessage). I currently have the class file in both the client library and EJB library and this is working. However I would like to have only one location for the class file where both the client and MDB can access it.开发者_开发知识库 I believe I need to package the entire app in a certain way, but I having a hard time figuring it out.

Any help will be greatly appreciated.

Thank you.


Typically most, if not all codesources (the locations from where classes are loaded) utilized by the application server's classloaders are located within the application server installation. In case of MDBs (or EJBs) for that matter, the codesources are contained within the EJB module (the EJB JAR file) or within the application archive (the EAR file). At runtime, the container manages where and how this code source is managed (including it's location), and there might not be a straightforward way to determine this location. In other words, it would be extremely difficult to use the deployed JARs in the container, in the classpath of your client application (assuming they are on the same machine).

The only possible way, I could think of using the same JARs in both the client app and by the application on the server, is to have a custom classloader on the server, that is configured to read specific classes from a common shared JAR. As a best practice, the classloader should always defer loading of classes to the parent classloaders, before attempting to resolve any class.

Your client may then, use the same shared JAR by setting the appropriate classpath (or by using the same custom classloader).

I should warn you that writing a custom classloader is not easy for some who haven't understood the classloading dynamics in a Java EE application server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜