Dynamic Class Loading problem


Industry news: Dynamic Class Loading problem

  1. Dynamic Class Loading problem (1 messages)

    Help Please.

    I’m currently having problems working with dynamic class loading in so far as I consistently get a ClassNotFoundException on attempting to load a class.

    I’ve included below the code sample I’ve been using that I extracted from an article Understanding Class.forName (white Paper) that I downloaded from this site at-.


    Using the example below I attempt to load a simple class named TmZome that I’ve placed in both the current directory and in my CLASSPATH but still receive the following exception on running the ClassLoader.

    java.lang.ClassNotFoundException: TmZone.class
    at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at spectraejb.ClassLoaderHelper$1.loadClass(ClassLoaderHelper.java:22)
    at spectraejb.ClassLoaderHelper.loadClass(ClassLoaderHelper.java:28)
    at spectraejb.ClassLoaderHelper.main(ClassLoaderHelper.java:54)
    Exception in thread "main"

    I’m assuming this is something quite simple that I’m missing on, but any pointers would be greatly appreciated.

    Ultimately I intend to implement the class loader in an application running on Oracle 10gAs should that imposes any further considerations.


    interface VMClassLoader {
      public Class loadClass(String cls) throws ClassNotFoundException;

    public class ClassLoaderHelper {
      private static VMClassLoader vmClassLoader;
      static {
        vmClassLoader = new VMClassLoader() {
          public Class loadClass(String cls) throws ClassNotFoundException {
            Thread t = Thread.currentThread();
            ClassLoader cl = t.getContextClassLoader();
            return cl.loadClass(cls);

      public static Class loadClass(String cls) throws ClassNotFoundException {
        return vmClassLoader.loadClass(cls);

      public static java.lang.reflect.Method getMethod(Class clazz, String name) throws
            Exception {
          java.lang.reflect.Method[] methods = clazz.getMethods();
          for (int i = 0; i < methods.length; i++) {
            if (methods[i].getName().equals(name)) {
              return methods[i];
          return null;

      public static void main(String[] args) throws Exception {

      Class clazz =

          // java.lang.reflect.Method method =
         // getMethod(clazz, "main");

      // method.invoke(null, new Object[] {newArgs});

  2. Dynamic Class Loading problem[ Go to top ]

    Hi Gary,
    Please note that Oracle Application Server does not use CLASSPATH environment variable. You have to put your in j2ee/home/lib directory to be picked up by the Server or package in the application.

    Please look at the Classloading Whitepaper at http://otn.oracle.com/tech/java/oc4j/pdf/ClassLoadingInOC4J_WP.pdf

    Hope that helps !

    Debu Panda