Loading a JAR file in JBoss 6 with Reflection

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
    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?


You can only refer to classes that are in the Jboss classpath. So if the jar is not loaded by jboss there is no way you load it.

Need Your Help

Informative sentences from words

java android algorithm

I have some words like "Arizona", "Jhon called smith", "Morning","jogging" ,I wanna sentence as"Jhon called smith from Arizona while jogging in morning"

Download artifact from Jenkins using PowerShell

powershell jenkins webclient

I try download artifact from Jenkins using PowerShell, like this: