mtcmedia
asked on
URLClassLoader How To Use?
/* Extract Classes From Jar */
myATP.extractFromJar(fileL ist1, jarFile);
/* Load Classes Into JavaVM */
pathname = jarFile.getPath();
workingDir = new URL(pathname);
urls[0] = workingDir;
try {
loader = new URLClassLoader(urls);
loader.findClass("Agent.cl ass");
loader.findClass("tcpClien t.class");
} catch (Exception e) {
System.out.println(e);
}
I get errors with both the loader.findClass lines, the error is:
testReceive.java:59: findClass(java.lang.String ) has protected access in java.net.URLClassLoader
myATP.extractFromJar(fileL
/* Load Classes Into JavaVM */
pathname = jarFile.getPath();
workingDir = new URL(pathname);
urls[0] = workingDir;
try {
loader = new URLClassLoader(urls);
loader.findClass("Agent.cl
loader.findClass("tcpClien
} catch (Exception e) {
System.out.println(e);
}
I get errors with both the loader.findClass lines, the error is:
testReceive.java:59: findClass(java.lang.String
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or skip extracting the files from the jar and do the following:
workingDir = new URL("jar:file:///" + pathname);
URClassLoader loader = new URLClassLoader(new URL[]{workingDir});
loader.loadClass("Agent.cl ass"); // provided Agent.class is defined in the default package, otherwise its package is needed as well
workingDir = new URL("jar:file:///" + pathname);
URClassLoader loader = new URLClassLoader(new URL[]{workingDir});
loader.loadClass("Agent.cl
Use loadClass(..), or better yet, Class.forName(String className, boolean initialize, ClassLoader loader);