I'm trying to load a class from a JAR file using reflection. This JAR file has a class that implements an Interface that is in a different JAR file. The JAR file that contains the interface is known by the project, since it is in its build path. This JAR file is also in two folders of JBoss 6, which are "client" and "common/lib".
The problem happens when I try to load the class dynamically to create an object, using the loadClass method of the class java.net.URLClassLoader. An ClassNotFoundException is thrown with regards to the interface that is shared by both the project and the JAR file. I'm obtaining the ClassLoader through the following method:
public static ClassLoader getClassLoader(final String fileName) {
final File file = new File(fileName);
URL url;
ClassLoader classLoader = null;
try {
url = file.toURL();
final URL[] urls = new URL[]{url};
classLoader = new URLClassLoader(urls);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return classLoader;
}
I have to load the class using this ClassLoader because the class is the File variable, which contains a reference to the JAR, which is not in JBoss.
Do I have to include the JAR with the Interface in a different folder of JBoss?