I'm trying to use Javassist to load an abstract method class that is dynamically loaded from a JAR file at runtime. For some reason, this code only runs on the Windows operating system. I get a ClassDefNotFoundException on any other platform. This is the code I used.
public static void example() throws Exception {
String pathToJar = "pathToJar.jar";
File JARFile = new File(pathToJar);
ClassLoader classLoader = URLClassLoader.newInstance(new URL[]{ JARFile.toURI().toURL() });
Class<?> callBackClass = classLoader.loadClass("package.Callback");
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(callBackClass);
MethodHandler handler = new MethodHandler() {
@Override
public Object invoke(Object self, Method overridden, Method forwarder,
Object[] args) throws Throwable {
return forwarder.invoke(self, args);
}
};
factory.setFilter(
new MethodFilter() {
@Override
public boolean isHandled(Method method) {
return Modifier.isAbstract(method.getModifiers());
}
}
);
Object instance = factory.create(new Class<?>[0], new Object[0], handler); /*exception thrown here on non-windows OS*/
}
Is this a problem with the class loader? Or is it a problem with Javassist? It's supposed to be platform independent, but depending on the OS, it may or may not run.