Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading a helper class in j2ee as shared resources and how to re-deploy/reload it ?

 
Hastono Bayu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i need help concerning classloading in j2ee

i have one EAR, which consists several EJB-JAR files. In each of the JAR files i need to load some helper class as a shared resources (others jar can access it)

i put this helper class in a directory. Then i added this directory to the system classpath. The classloading works fine.
But the problem is i need to change this helper class and refresh the class without restarting the server. when i invoke the class, it called the old instances of the class, even i've replaced the file on the directory that hold it. What's happening ?

Can u help me to solve this thing out ? Or should i put the helper class inside the EAR too ? how i should call this helper class inside the EAR for each separated JAR ?
Need all ur help...

Regards,


Bayu
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Hastono Bayu:
But the problem is i need to change this helper class and refresh the class without restarting the server. when i invoke the class, it called the old instances of the class, even i've replaced the file on the directory that hold it. What's happening ?

If your classes are on the System Classpath then restarting the server is the only thing that will cause them to reload. What you are seeing is completely normal behavior.

Originally posted by Hastono Bayu:
Can u help me to solve this thing out ? Or should i put the helper class inside the EAR too ? how i should call this helper class inside the EAR for each separated JAR ?

You basically have three options here:

1) Put all shared classes on the System CLASSPATH.
2) Put all shared classes in each ejb-jar.
3) Put all shared classes in a jar in the ear and place a manifest dependency between each ejb-jar and the shared jar.

Option 1 is what you are currently doing, however as you noticed it prevents dynamic reloading of the shared classes.

Option 2 is fairly easy, however it requires all ejbs to be redeployed if a single shared class changes and offers room for error if all ejb-jars are not updated. A good automated build process is definitely necessary here (Ant)...

Option 3 is the solution that I recommend and is required behavior in J2EE 1.3. However, not all tools support the manifest entry so it may be a pain to configure builds. As with option 2, I highly recommend an automated build using Ant.

For more information I suggest you take a look at these two articles by Tyler Jewel:
EJB 2.0 and J2EE Packaging
EJB 2.0 and J2EE Packaging, Part II
 
Hastono Bayu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, Thanx A lot..
I've figured out by placing the shared library in the EAR, so each JAR in the same EAR can use it. (Options #3)
I found it as quite easy practice using Sun App Server with the deploytool they provided.

Litlle more question : How about if i have two EAR using the same dynamic class library ?
Where should i put the library ?
Should it be in both EAR ?
As far as i learn, i need to put it in the server classpath (server clasloader) so both EAR can recognized it.. but again that will block the dynamic reloading process.

Any suggestion ??

Thanx in advance,


Bayu
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 35762
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bayu,
Yes, you would have two copies of the jar - one in each ear. This also lets you update the ears independently if you ever want to change versions of the jar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!