Not sure if it fits the objective of this project. It would be nice if the Jar classloader could support adding individual classes one by one with byte[] / ByteArrayInputStream.
I've added the two following two methods :
- JarClassLoader
public void addClass(String fullClassName, byte[] bytes){
classpathResources.loadClass(fullClassName, bytes);
}
- ClasspathResources
/**
* Read an individual class as byte[]
*/
public void loadClass(String entryName, byte[] bytes){
entryName = entryName.endsWith(".class") ? entryName : entryName + ".class";
entryName = entryName.indexOf('.')<0? entryName:
entryName.substring(0,entryName.length()-".class".length()).replaceAll("\\.", "/") + ".class";
jarEntryContents.put(entryName, bytes);
}
The 2nd method has a bit intelligent to handle the use of package name/path and with/without ".class' suffix.
diff against the svn trunk