My code returns java.lang.ClassNotFoundException: and I don't really understand why this is happening. I want to extract classes from a JAR and load them in an URLClassLoader object together with their instrumented version.
To obtain the instrumented version, the bytecode is saved to a file after is being modified. The snippet describes the algorithm. The classes from the JAR are successfully loaded in the classloader however the instrumented bytecode files saved on the disk don't get loaded even if the path to them is specified.
private URL[] urls;
private URLClassLoader classLoader;
private HashMap<String, Class> classNames;
// initialise ClassLoader
File file = new File(System.getProperty("user.dir") +"/instr_vers/");
this.urls = new URL[]{new URL("jar:file:" + jarPath + "!/"), file.toURI().toURL()};
this.classLoader = new ClassLoader(urls);
// for every entry in the JAR
while(jar.HasEntry()){
Class<?> normalVersion = classLoader.loadClass(className);
classNames.put(className, normalVersion);
byte[] instrBytes = myMethod.instrumentClass(normalVersion);
// class, path
SaveClassToFile(instrBytes, new File(System.getProperty("user.dir") +"/instr_vers/" + className + "intr_version" ));
Class<?> instrVersion = classLoader.loadClass(className); // line with exception
classNames.put(className + "_intr_version", instrVersion);
}
Aucun commentaire:
Enregistrer un commentaire