Extending J2EE application with 3rd party classes

Discussions

General J2EE: Extending J2EE application with 3rd party classes

  1. Hello,
    I would like some design advice. We have a J2EE application packaged in an EAR file. One module in the application (a stateless session EJB) loads a Java class by its name. The names classes to load are stored in the database.

    We would like to enable 3rd parties to extend our application by adding their own class names to the database and then the above module should automatically load them. The problem is that if the class is not packaged in an EAR file, we will get a ClassNotFound exception when the EJB module calls Class.forName(xxx). There are reasons it is desirable for us to enable 3rd parties to add their own classes without having to package them up into our EAR file:
    1) it is a cumbersome process of unzipping the EAR file, adding your class and then zipping the EAR file again
    2) dealing with software patches becomes a nightmare: if we wanted to patch our EAR file at the customer site, we no longer can just replace the old EAR with the new one - we need to be careful not to loose 3rd party changes.

    Anyway, to make a long story short, I am looking for recommendations on how to allow people to add their classes to our application.

    By the way, we use BEA Weblogic 6.1 and Websphere 4.0.5 application servers.
    Thanks in advance
    Greg
  2. It looks to me that you need to write you own classloader. This isn't to hard, but you might run in trouble with the SecurityManager...

    Regards,
    Barri
  3. Hi Barri,
    Could you elaborate on that a little bit? I.e. what special functionality would this class loader have to have? I don't mind doing the work if it is the right thing to do.

    Thanks a lot
    Greg

    P.S. One of the highly desired "features" of this whole thing that I did not mention in my original message is that if the 3rd party classes live in a jar file(s), then in a clustered environment the customer would not have to update all the nodes in the cluster, just the one "master" node and then all the other nodes authomatically get an update. This is precicely what happens when you need to patch an EAR file under Weblogic server. Therefore we would really like it that if the 3rd party classes lived in some other jar file, the mechanism would also apply.
  4. I'm not sure if Weblogic or any appserver provides this kind of functionallity.
    I think you need to write this kind of functionality yourselve. With a custom classloader you can load a class from a (jar)-file/url/or even a database. this isn't to hard to do.

    Take a look at this example:
    http://www4.informatik.uni-erlangen.de/Lehre/WS00/V_OODS1/Tutorial/6-A6.pdf

    You should keep in mind that you also keep track of newer versions of classes. Then recreate your classloader and reload the classes.

    Hope this helps,

    Barri