Replacing system class loader

Hi!
I'm trying to replace the system class loader for plugin management reasons. I've written a simple test app for testing, but it doesn't work. The first code is a ClassLoader, the second is the main code.
I try to run the code like this: java -Xbootclasspath/a:. -Djava.system.class.loader=A -cp . B
It uses my classloader every time, except for when I call Class.forName(). What could be the problem?
Thanks, Bal�zs
public class A extends java.lang.ClassLoader {
public A(ClassLoader parent) {
super(parent);
System.out.println("A loaded, parent is " + parent);
public Class loadClass(String name) throws java.lang.ClassNotFoundException {
try {
Class c = getParent().loadClass(name);
System.out.println("A was asked for " + name + " and delegated it to " + getParent());
return c;
} catch (ClassNotFoundException e) {
System.out.println("A was asked for " + name + " but didn't find it");
throw new ClassNotFoundException(name + " not found :[");
}; // ENDOF CLASS A
public class B {
public static void main(String[] args) {
(new B()).proc();
private void proc() {
System.out.println("Hello World!");
System.out.println("Class loader: " + getClass().getClassLoader());
try {
Class.forName("C");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}; // ENDOF CLASS B

Thanks for the reply. I think I've got a much better idea of how this stuff works now. I think what I need to do is register my deserializer with SOAP as a class that will really load the deserializer using Class.forName() with my class loader as a parameter. Then when the bootstrap class loader can't find a class, findClass() in my classloader will be called and I can load it from a URL.
Should work.
Thanks very much!

Similar Messages

  • How to load a class dynamically in the current/system class loader

    I need to dynamically load a new jdbc driver jar to the current/system class loader... Please note that creating a new classloader will not help since the DriverManager refers to the systemclassloader itself.
    Restarting the application by appending the jar to its classpath will solve the problem but I want to avoid doing this.

    Did you then create a ClassLoader to load the JDBC
    driver and then install it into the system as
    directed by the JDBC specification (ie
    Class.forName(someClassName))?
    And then try to use it from a class loaded fromsome
    other ClassLoader (i.e. the system class loader)?
    If you did not try this please explain why not.O.K. I just looked at the source to
    java.sql.DriverManager. I did not know what I was
    talking about, as what I suggested above will not
    work.
    This is my new Idea:
    Create a URLClassLoader to load the JDBC driver also
    in this ClassLoader you need to place a helper class
    that does the following:
    public class Helper {
    public Driver getJDBCDriver(String driverClassName,
    String url) {
    try {
    Class.forName(driverClassName);
    Driver d = DriverManager.getDriver(url);
    return d;
    catch(Exception ex) {
    ex.printStackTrace();
    return null;
    }Now create an instance of the Helper class in the new
    ClassLoader, and call its getJDBCDriver method to get
    an instance of the driver (you will probably have to
    create an interface in the root class loader that the
    Helper implements so that you can easily call it).
    Now from the root classloader you can make calls
    directly to the returned Driver and bypass the
    DriverManager and its restrictions on cross
    ClassLoader access.
    The only catch here is that you would have to call to
    the returned Driver directly and not use the Driver
    Manager.This sounds like will work but I did not want to load DriverManager in a new classloader.. I did a hack
    I unzip the jar dynamically in a previously known location (which I included in my classpath when launching the app). The classLoader finds the class now though it did not exist when the app was launched !
    A hack of-course but works eh ..

  • System class loader vs application class loader

    Hello
    I have a class that uses a third partyjar which I have put in /jre/lit/ext. The class compiles but fails at runtime being unable to read the property files called in the class' constructor. I believe that is b/c the third party jars are loading w/ the system class loader and cannot "see" the property files "floating" at the same level as the class that is calling them.
    So I created a jar, of the property files, with the same directory/package structure as the location of the property files and put that in the /jre/lib/ext and STILL the same problem; cannot read the property files, the constructor fails, fugly. There is an overloaded constructor that includes a parameter for the property files, but I need to get this to work as is first. What am I missing? Please edify me. tia.

    If the 3rd party jar needs a certain properties file to initialize correctly, I doubt it would be looking for it in the class hierarchy. I mean I doubt it does:
    Properties p = new Properties();
    p.load( getClass().getResourceAsStream() );It's more likely to do:
    Properties p = new Properties();
    p.load( new FileInputStream(...) );The reason is that the property file should be easily edited by the user and users know how to move around in the file system, not in the Java jars and classpaths.
    Just a guess...

  • Why won't -Djava.system.class.loader make it use my ClassLoader?

    I created a class MyAppLoader and installed it in the bootclasspath and used the system property -Djava.system.class.loader. Yet, the JVM won't use my classloader! It's never instantiated (I have a static bit that prints code if it's loaded at all).
    How do I make the JVM use my class as the system classloader?

    send to me some Duke, please Any particular one? I hear the Duke of Northumberland is quite a laugh - would he do?

  • Problem loading modified classes from CLASSPATH using system class loader

    Hi,
    I am facing problem to load the modified classes from CLASSPATH.
    I have set my CLASSPATH to a directory whose classes will be modified frequently. After the server(web/app) is started, the system class loader, using which am trying to load the classes from the directory where the CLASSPATH is set, am not able to load the modified files without the server restart.
    Do I need to have a custom class loader to fix this.
    Please help me.
    Thanks,
    Sureddy

    Do I need to have a custom class loader to fix this.Yes.

  • Can I set Boot class loader or system class loader?

    In my application, there are classes in a jar files, all these files in the jar need be loaded by a ClassLoader in my application.
    And the classes out of jar do not need the ClassLoader to load. the structure is like :
    -----myapp.jar ------in this jar, all classes need be loaded by a specified ClassLoader
    |---anoapp ------classes in this package, is normal classes
    |-------|----a.class
    |----b.class
    | ----other classes
    but my a.class need to access a class in myapp.jar, so I load the class use my ClassLoader, but there still occur
    **********ClassFormatError : bad magic number**************
    I print the classloader in a.class
    +---- System ClassLoader is : com.sun.misc.Launcher$AppClassLoader    ------------it is not my ClassLoader
    +---- a.class.getClassLoader is same as System ClassLoader    -------------------it still is not my ClassLoader
    +---- Thread.currentThread().getContextClassLoader          ------------------ it is my ClassLoader
    So I think when I access class in myapp.jar, it will loaded by System ClassLoader or Bootstrap ClassLoader, if I can set one these two classloader as my ClassLoader, it maybe not occur the Error,
    But There are not obvious method in System or Runtime etc.
    1. So can Set System Classloader or Bootstrap ClassLoader?
    2. If not, How can solve my problem?
    Thands in advanced!

    **********ClassFormatError : bad magic number**************If you get that error, then no classloader will help you. This is a problem with your running code meant for a newer version of the Virtual Machine in an older version.
    Looks like you're compiling the code with a recent JDK (1.4.x?), but running with an older VM. Try just typing "java -version" and see what it prints.
    This should just be a matter of running with the right VM. If this is an applet you're trying to run inside the browser, make sure that the browser is using the right VM. Run the "Java Control Panel" and select the correct version.

  • Application Class Loader problem calling virtual function

    Hello everyone
    I have run in to very strange behavior of JVM
    I have created a class loader which allows my to load classes from
    jar file, regardless that URLClassLoader supplies this functionality.
    I am using this class loader to load some classes and call their virtual functions. The class diagram looks like that:
    public interface I {
       public void init();
    public class AAA implements
       public void init(){
    public class BBB extends AAA{
       public void init(){
          //here comes implementation
    }Interface I and class AAA are loaded with System Class loader and Class BBB is loaded using my class loader from jar file.
    ByteStreamClassLoader  classLoader =  new ByteStreamClassLoader  ();
    Class cl = classLoader. loadClass(�com.product.BBB�,true);
    I myInterface = cl.newInstance();
    myInterface.init();The problem is that from some unknown reason java class AAA.init() instead of BBB.init().
    Can somebody help me what am I doing wrong?
    Class Loader code attached below
      public class ByteStreamClassLoader   extends ClassLoader {
        protected HashMap m_cache = new HashMap();
        public void clearCashe() {
          m_cache = new HashMap();
        private String definePackage(String className) {
          StringBuilder strB = new StringBuilder();
          //Class name must be removed from the URI in order to define a package
          String[] packageArray = className.split("\\.");
          for (int i = 0; i < packageArray.length - 1; i++) {
            strB.append(packageArray).append(".");
    String packageName = strB.toString();
    packageName = packageName.substring(0, packageName.length() - 1);
    if (getPackage(packageName) == null) {
    m_logger.log(Level.FINEST, "Defining package '" + packageName + "'");
    definePackage(packageName, null, null, null, null, null, null, null);
    return packageName;
    public synchronized Class loadClass(String name, boolean resolve) throws
    ClassNotFoundException {
    name = name.replaceAll("/", ".").replaceAll(".class", "");
    //Try to locate the Class in cashe
    Class c = (Class) m_cache.get(name);
    //Try to locate the Class in the System Class Loader
    if (c == null) {
    try {
    c = ClassLoader.getSystemClassLoader().loadClass(name);
    catch (Exception ex) {}
    else {
    m_logger.log(Level.FINEST, "Class '" + name + "' found in cache");
    //Load the class from byte array
    if (c == null) {
    String resourceName = name;
    if (!resourceName.endsWith(".class")) {
    resourceName = resourceName.concat(".class");
    //Retrieve class byte representation
    if (resourceName.indexOf(".") != -1) {
    resourceName =
    resourceName.replaceAll("\\.", "/").replaceAll("/class", ".class");
    //Use the ByteStreamClassLoader to load the class from byte array
    byte[] classByteArray = null;
    try {
    classByteArray = getResourceBytes(resourceName);
    catch (IOException ex1) {
    throw new ClassNotFoundException(
    "Could not load class data." + ex1.getMessage());
    m_logger.log(
    Level.FINEST, "Loading class '" +
    name + "' Byte Length: " + classByteArray.length);
    String p = definePackage(name);
    c = defineClass(
    name,
    classByteArray,
    0,
    classByteArray.length,
    ByteStreamClassLoader.class.getProtectionDomain());
    m_cache.put(name, c);
    if (resolve) {
    resolveClass(c);
    return c;

    Hello everyone
    I have run in to very strange behavior of JVM
    I have created a class loader which allows my to load classes from
    jar file, regardless that URLClassLoader supplies this functionality.
    I am using this class loader to load some classes and call their virtual functions. The class diagram looks like that:
    public interface I {
       public void init();
    public class AAA implements
       public void init(){
    public class BBB extends AAA{
       public void init(){
          //here comes implementation
    }Interface I and class AAA are loaded with System Class loader and Class BBB is loaded using my class loader from jar file.
    ByteStreamClassLoader  classLoader =  new ByteStreamClassLoader  ();
    Class cl = classLoader. loadClass(�com.product.BBB�,true);
    I myInterface = cl.newInstance();
    myInterface.init();The problem is that from some unknown reason java class AAA.init() instead of BBB.init().
    Can somebody help me what am I doing wrong?
    Class Loader code attached below
      public class ByteStreamClassLoader   extends ClassLoader {
        protected HashMap m_cache = new HashMap();
        public void clearCashe() {
          m_cache = new HashMap();
        private String definePackage(String className) {
          StringBuilder strB = new StringBuilder();
          //Class name must be removed from the URI in order to define a package
          String[] packageArray = className.split("\\.");
          for (int i = 0; i < packageArray.length - 1; i++) {
            strB.append(packageArray).append(".");
    String packageName = strB.toString();
    packageName = packageName.substring(0, packageName.length() - 1);
    if (getPackage(packageName) == null) {
    m_logger.log(Level.FINEST, "Defining package '" + packageName + "'");
    definePackage(packageName, null, null, null, null, null, null, null);
    return packageName;
    public synchronized Class loadClass(String name, boolean resolve) throws
    ClassNotFoundException {
    name = name.replaceAll("/", ".").replaceAll(".class", "");
    //Try to locate the Class in cashe
    Class c = (Class) m_cache.get(name);
    //Try to locate the Class in the System Class Loader
    if (c == null) {
    try {
    c = ClassLoader.getSystemClassLoader().loadClass(name);
    catch (Exception ex) {}
    else {
    m_logger.log(Level.FINEST, "Class '" + name + "' found in cache");
    //Load the class from byte array
    if (c == null) {
    String resourceName = name;
    if (!resourceName.endsWith(".class")) {
    resourceName = resourceName.concat(".class");
    //Retrieve class byte representation
    if (resourceName.indexOf(".") != -1) {
    resourceName =
    resourceName.replaceAll("\\.", "/").replaceAll("/class", ".class");
    //Use the ByteStreamClassLoader to load the class from byte array
    byte[] classByteArray = null;
    try {
    classByteArray = getResourceBytes(resourceName);
    catch (IOException ex1) {
    throw new ClassNotFoundException(
    "Could not load class data." + ex1.getMessage());
    m_logger.log(
    Level.FINEST, "Loading class '" +
    name + "' Byte Length: " + classByteArray.length);
    String p = definePackage(name);
    c = defineClass(
    name,
    classByteArray,
    0,
    classByteArray.length,
    ByteStreamClassLoader.class.getProtectionDomain());
    m_cache.put(name, c);
    if (resolve) {
    resolveClass(c);
    return c;

  • Dynamic Class Loading in an EJB Container

    Hello,
    We have a need to load classes from a nonstandard place with in an ejb container, ie a database or secure store. In order to do so we have created a custom class loader. Two issues have come up we have not been able to solve, and perhaps some one knows the answer to.
    Issue 1.
    Given the following code:
    public static void main(String args[])
    MyClassLoader loader = new MyClassLoader("lic.dat");
    System.out.println("Loading class ..." + "TestObject");
    Object o = Class.forName("TestObject",true,loader).newInstance();
    System.out.println("Object:" + o.toString());
    TestObject tstObj = (TestObject) o;
    tstObj.doIt();
    What happens when executed is as follows. Class.forName calls our loader and does load the class as we hoped, it returns it as well, and the o.toString() properly executes just fine. The cast of the object to the actual TestObject fails with a class not found exception. We know why this happens but don't know what to do about it. It happens because the class that contains main was loaded by the system class loader (the primordial class loader as its sometimes called), That class loader does not know about TestObject, so when we cast even though the class is "loaded" in memory the class we are in has no knowledge of it, and uses its class loader to attempt to find it, which fails.
    > So the question is how do you let the main class know to use our class loader instead of
    the system class loader dispite the fact is was loaded by the system class loader.
    Issue 2:
    To make matters worse we want to do this with in an EJB container. So it now begs the question how do you inform an EJB container to use a specific class loader for some classes?
    Mike...

    Holy crap! We are in a similar situation. In creating a plugin engine that dynamically loads classes we use a new class loader for each plugin. The purpose is so that we can easily unload and/or reload a class at runtime. This is a feature supposedly done by J2EE app servers for hot-deploy.
    So our plugins are packaged as JAR files. If you put any class in the CLASSPATH, the JVM class loader (or the class loader of the class that is loading the plugin(s)), will load the class. The JavaDoc API states that the parent classloader is first used to see if it can find the class. Even if you create a new URLClassLoader with NULL for parent, it will always use the JVM class loader as its parent. So, ideally, in our couse, plugins will be at web sites, network drives, or outside of the classpath of the application and JVM.
    This feature has two benefits. First, at runtime, new updates of plugins can be loaded without having to restart the app. We are even handling versions and dependencies. Second, during development, especially of large apps that have a long startup time, being able to reload only one plugin as opposed to the annoying startup time of Java apps is great! Speeds up development greatly.
    So, our problem sounds just like yours. Apparently, the Client, which creates an instance of the plugin engine, tries to access a plugin (after the engine loades it via a new classloader instance for each plugin). Apparently, it says NoDefClassFound, because as you say, the client classloader has no idea about the plugin class loaded by another classloader.
    My co-developer came up with one solution, which I really dont like, but seems to be the only way. The client MUST have the class (java .class file) in its classpath in order to work with the class loaded by another class loader. Much like how in an EJB container, the web server calling to EJB MUST contain the Home and Remote interface .class files in its classpath, the same thing needs to be done here. For us, this means if a plugin depends on 5 others, it must contain ALL of the .class files of those plugins it depends on, so that the classloader instance that loads the plugin, can also see those classes and work with them.
    Have you got any other ideas? I really dislike that this has to be done in this manner. It seems to me that the JVM should be able to allow various class loaders to work with one another in such a way that if a client loaded by one classloader has an import statement in it to use a class, the JVM should be able to fetch the .class out of the other classloader and share it, or something!
    This seems to me that there really is no way to actually properly unload and then reload a class so that the JVM will discard and free up the previous class completely, while using the new class.
    I would be interested in discussing this topic further. Maybe some others will join in and help out on this topic. I am surprised there isn't a top-level forum topic about things like class loaders, JVM, etc. I wish there was a way to add one!

  • Class Loader Issues

    I am dynamically creating .class files on the fly in my application. Often I need to rebuild the same class (including client classes) multiple times. The problem is that the system ClassLoader keeps the 1st .class file in memory and will not return to the disk to retrieve the new version after the class file(s) have changed.
    Do I need to write a new Classloader and substitute it for the main systems class loader? Is there a better way to instantiate the class other than Class.forName( blah ) that will solve this problem?
    Thanks,
    -Jeff Harman

    Like we told you. If the code for a class changes, Java will not automatically notice and load the new version, until you start up the JVM again. If you do not want to re-start the VM, you can create a new ClassLoader (CL), and use it to load the new code for the class.
    Now, the problem is, the second CL may think it has to reload many of other classes, since it has no record of loading them itself. You will end up with duplicates of many classes.
    If that doesn't suit you, there is not much alternatives.
    You could rename the new version of the class, which would mean you'd have to manually track down all the old versions and upgrade them ( by using the new Ctor). You'd then have to update all the references to make them point to the new object. You can make that particular job easier by making both classes (old and new) extend a common base class, or implements the same interface, and use the interface reference (i.e program to an interface).
    Another less-than-perfect possibility would be to use serialization where you serialise version-marked objects and reconstitute them with new code...
    Good luck.

  • Class Loader Troubles

    Hi all,
    I am using a URLClassLoader to dynamically load a class during a program's execution. This works fine. However, when I try to load classes later on in the code, it still tries to use the URLClassLoader. Is there some variable I need to set to get back to using the default System class loader?
    Thanks,
    ottobonn

    Alright,
    I am loading a class, which extends Plugin (which I created). The Plugin.class file resides in the main jar of my application. Outside the jar, I also have a folder, called "plugins". This holds 3rd-party classes, which I want to load dynamically. I am using a URLClassLoader, with code like the following:
    //pluginDirectoryString will have the location of the plugins folder
    try{
      pluginDirectory = new URL(pluginDirectoryString);
    }catch(MalformedURLException mfurle){
      System.out.println("Malformed URL: " + pluginDirectoryString);
      mfurle.printStackTrace();
    URL[] urls = new URL[1];
    urls[0] = pluginDirectory;
    URLClassLoader loader = new URLClassLoader(urls);
    Plugin p = (Plugin)loader.loadClass(name).newInstance();When I run this code, I get an exception saying that the class "Plugin" could not be found:
    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: Plugin
    Caused by: java.lang.ClassNotFoundException: Plugin
    //...I think the URLClassLoader is trying to find the Plugin class when I typecast. However, I want the system to load the Plugin class with the original class loader. Do I need to include the original directory in the array of URLs?

  • Class loader question

    Hi,
    I got NoClassDefFoundError and when I use ClasspathDebug jsp it shows that the class is loaded by "java.net.URLClassLoader". I put the jar file containing the class in <domain>/lib directory. According to docs the jar under <domain>/lib should be loaded by system class loader. what is "java.net.URLClassLoader"? why isn't system loader loading my class? I am using wls91. Thanks
    weblogic.servlet.jsp.TagFileClassLoader
    weblogic.utils.classloaders.ChangeAwareClassLoader
    weblogic.utils.classloaders.GenericClassLoader
    weblogic.utils.classloaders.GenericClassLoader
    java.net.URLClassLoader
    sun.misc.Launcher$AppClassLoader
    sun.misc.Launcher$ExtClassLoader
    Bootstrap classloader

    I'm not sure from reply 2 whether you figured out what's going on or not. It sounds like you did, but just in case...
    The null/primordial/bootstrap class loader loads classes in the core API--stuff it finds in the ext dir(s?) (e.g. rt.jar)--Object, String, java.util.*, java.sql.*, etc. It has no parent. It is the root of the normal delegating classloader tree.
    The system classloader is the one that uses classpath to load your classes and 3rd party classes. Everything not in the core API, as long as neither you nor those other classes explicitly specify a different classloader.
    The way the normal delegation mechanism works is that a request to load a class is first passed to the loader that loaded the current class. This loader first gives its parent a chance to load it, and so on up the tree to the primordial loader.
    Once it hits the root (null/primordial/bootstrap), that classloader tries to load it. If it can't (and the primordial loader can't, in fact, load your class, since it's not in the ext dir), then it hands it back to its child. This continues down the line, with the parent getting first shot at loading, then the child trying if the parent fails.
    The primordial loader (which loaded the JdbcOdbcDriver) can't load your class. It hands it back to its child--the system classloader--which can and does load it, using classpath.
    I hope that answers any lingering questions, if there were in fact such questions.

  • Class loader: saaj-api conflict

    I need to load saaj-api from my application which is newer than the one that comes w/ith oc4j 10.1.3 which is loaded by the system class loader with name api from webservices/lib/saaj-api.jar.
    remove-inherited doesn't seem to do the trick.
    Any suggestions would be appreciated.
    Thanks,
    Jindong.

    While I understand where you're coming from, it sounded to me that oc4j lacks the flexibility to allow application to use newer version of certain component.
    For example, certain JDK level supports certain JAXP, but there is indeed an extension mechnism to allow application plug in newer JAXP?
    I believe other j2ee contains are a lot flexbile in terms of this...I don't think J2EE spec says that applications running in its container can not use newer software components?
    I think it only makes sense that the minimum supported level is j2ee 1.4, but nothing should stop applications from having their own version of any thing.
    I strongly suggest that this to be considered for what ever release you guys are working on or a work around can be provided for the current version we're using.
    Jindong.

  • Class Loader Differences

    Hi!
    I found differences in beheviour of system class loader and OJSP class loader.
    The problem is:
    when I place jar's in web-inf\lib directory I get message about impossibility to find classes (not all, just some).
    When I use servlet engine wrapper.classpath parameter evething works fine.
    Any comments will be appreshiated
    Mike

    You may have encountered bug 1625520 -
    JSPC DOES NOT USE INCLUDE CLASSES UNDER
    WEB-INF DIRECTORIES .
    The bug was recently fixed (version 1.1.2.1
    which should be going out with the 9i database or that or a higher version of the
    OJSP should be going out on OTN shortly.
    By shortly, I'm guessing beginning of
    April.

  • Help Needed on a similar but not same class loader problem

    Hi,
    Please help...
    There is a ClassLoader called MyLoader that overrides default findClass() method to decrypt already encrypted class files available in a separate jar file.
    MyClass also contains a public static method launchMe() method that starts off with a call similar to loadClass("ApplicationMainClass");
    The MyLoader class is also encrypted
    I modified the default launcher (c) code to:
    First find the encrypted MyLoader file then decrypt it and create a byte array.
    The byte array, along with the system class loader and other required arguments, is passed to DefineClass native method (defined in jvm.dll)
    Note: The system class loader class has been instantiated using static method ClassLoader.getSystemClassLoader() through Java's invocation API.
    The DefineClass succeeds and I'm able to instantiate MyLoader and later call launchMe() to start application.
    Now i come to the problem:
    I'm not able to use any class other that those in rt.jar (i.e.standard classes) in MyLoader class. I end up with a runtime error ClassDefNotFoundError while trying to load any third party jar.
    The classes i need are present in class path and also in the local jre's ext that i use to launch my app.
    Although i can avoid using third party jar in MyLoader but if there is any way...
    Piyush

    make sure that third party jar resides in your library.....
    or else put rt.jar and external jars under same folder
    this is matter of path.... no else than this.......
    cheers
    Rajesh42

  • Class Loader confusion

    I am trying to use java.net.URLClassLoader to load classes dynamically from jar files. The strange thing is, I can only get this to work successfully with one particular Jar file. With any other Jar file I have tried, I get a java.lang.NoClassDefFoundError. I'm trying to figure out what is different about this particular jar file.
    The first thing I should point out is that when I create the URLClassLoader, I can successfully load the appropriate classes using loadClass(). So I am not mistyping the filename of the Jar or anything like that.
    It's only when I try to create an instance of a class that is not in the Jar but uses a class in the Jar file, that I get the NoClassDefFoundError.
    The second thing I have noticed is that everything works fine when run using the Sun JDK1.3 VM. It is only in my production environment (Lotus Notes) that the problem occurs. It seems the Notes class loader is doing things differently to the sun class loader. Perhaps this is a security issue?
    Can anyone shed any light on why this is occuring? Why does everything work fine with one particular Jar (Jakarta POI) but no others I have tried? And why does it stop working in the Notes environment?
    Any help is appreciated.
    And here is my code:
        public void test()
            URL[] urls=new URL[1];
            File file=new File("c:/software/libraries/tablelayout.jar");
            try
                urls[0]=file.toURL();
            catch (MalformedURLException e)
                e.printStackTrace();
                return;
            ClassLoader cl = this.getClass().getClassLoader();
            ClassLoader loader=URLClassLoader.newInstance(urls,cl);
            Class agentClass=null;
            try
                // Test if we can actually load the class
                Class testClass = loader.loadClass("com.lowagie.text.pdf.PdfReader");
                System.out.println("loaded test class");
                agentClass = loader.loadClass("test.RandomAgent");
            catch (ClassNotFoundException e)
                e.printStackTrace();
                return;
            AgentBase agent=null;
            try
                agent = (AgentBase) agentClass.newInstance(); // This is where the NoClassDefFoundError is thrown
            catch (Exception e)
                e.printStackTrace();
                return;
            agent.NotesMain();
        }And the stack trace I get:
    loaded test class
    java.lang.NoClassDefFoundError: com/lowagie/text/pdf/PdfReader
         at java.lang.Class.newInstance0(Native Method)
         at java.lang.Class.newInstance(Class.java:262)
         at TestAgentUsingClassLoader.NotesMain(TestAgentUsingClassLoader.java:64)
         at lotus.domino.AgentBase.runNotes(Unknown Source)
         at lotus.domino.NotesThread.run(NotesThread.java:218)

    I figured it out. Thanks to this post: http://forum.java.sun.com/thread.jspa?threadID=484866&messageID=2267796
    The class test.RandomAgent was actually being loaded by the system classloader, even though I had asked to create it using the URLClassLoader. The URLClassLoader delegates the creation to its parent (the system class loader) which found the test.RandomAgent class on the system class path. Thereon, all class created by the RandomAgent class would have been loaded by its ClassLoader, i.e. the system class loader.
    To fix this, I had to ensure the test.RandomAgent class was not on the system classpath. To do that, I had to put it in its own Jar and add that jar to the URLClassLoader list.
    It turned out that the reason it worked with one jar (Jakart POI) was that that Jar was on my system classpath! So that was a red herring.

Maybe you are looking for