Reputation:
from there, i using class loader to identified class from other directory
File dir=new File ("D:\\dirclass")
fulldir = new File (dir+"\\myclass");
filename = new StringTokenizer(fulldir.getName(), ".").nextToken();
URL[] checkclass =
{
dir.toURI().toURL()
};
URLClassLoader urlcl = new URLClassLoader(checkclass);
Class cls = urlcl.loadClass(filename);
this is worked if class without package.
but if class with package, failed to running.
Exception in thread "main" java.lang.NoClassDefFoundError: packclass (wrongname: dirclass\packclass)
is there any other way ?
Upvotes: 0
Views: 53
Reputation: 16041
You have to specify the fully qualified names of classes to the ClassLoader
, for example:
Class cls = urlcl.loadClass("com.mypackage.MyClass");
Upvotes: 1