Discussions

EJB programming & troubleshooting: Java Classloader

  1. Java Classloader (1 messages)

    I wrote a custom classloader to dynamically load classes
    present in a certain directory( *not* present in the CLASSPATH). ( So that I need not restart AppServer, everytime I add a new class)

    I am able to succefully load a class( say A.class), *BUT* when that class(A.class) uses other classes(B.class) present in that directory, then it is reporting classnotfound exception.

    I believe A.class is delegating the the work of finding B.class to the parent classloader instead of the "custom classloader".

    Is there any method, by which you can force a class to use the custom classloader or anything like that. Can anyone pls advise/suggest me what whould be a right approach
  2. Java Classloader[ Go to top ]

    Try setting your classloader as the context class loader for the thread you are in, and have your loader use the system loader as a parent and delegate for classes it can't find. Of course, if you are running in an EJB container you have to be careful not to do any of this from within an EJB or you are going against the spec.