Help Please.
Im currently having problems working with dynamic class loading in so far as I consistently get a ClassNotFoundException on attempting to load a class.
Ive included below the code sample Ive been using that I extracted from an article Understanding Class.forName (white Paper) that I downloaded from this site at-.
http://www.theserverside.net/developmentor/thread.tss?thread_id=25023
Using the example below I attempt to load a simple class named TmZome that Ive 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"
Im assuming this is something quite simple that Im 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.
Regards
Gary.
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 =
ClassLoaderHelper.loadClass(args[0]);
// java.lang.reflect.Method method =
// getMethod(clazz, "main");
// method.invoke(null, new Object[] {newArgs});
}
-
Dynamic Class Loading problem (2 messages)
- Posted by: Gary Cannell
- Posted on: September 30 2004 12:03 EDT
Threaded Messages (2)
- Dynamic Class Loading problem by Debu Panda on September 30 2004 12:42 EDT
- Re: Dynamic Class Loading problem by Gary Cannell on September 30 2004 18:16 EDT
-
Dynamic Class Loading problem[ Go to top ]
- Posted by: Debu Panda
- Posted on: September 30 2004 12:42 EDT
- in response to Gary Cannell
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 !
regards
Debu Panda
http://radio.weblogs.com/0135826/ -
Re: Dynamic Class Loading problem[ Go to top ]
- Posted by: Gary Cannell
- Posted on: September 30 2004 18:16 EDT
- in response to Debu Panda
Thanks Debu,
This appears to be a very useful document
Regards
Gary.