我现在在测试中实际上正在使用类似的方法,将一组类定义作为byte []给予ClassLoader:
public static class ByteClassLoader extends URLClassLoader { private final Map<String, byte[]> extraClassDefs; public ByteClassLoader(URL[] urls, ClassLoader parent, Map<String, byte[]> extraClassDefs) { super(urls, parent); this.extraClassDefs = new HashMap<String, byte[]>(extraClassDefs); } @Override protected Class<?> findClass(final String name) throws ClassNotFoundException { byte[] classBytes = this.extraClassDefs.remove(name); if (classBytes != null) { return defineClass(name, classBytes, 0, classBytes.length); } return super.findClass(name); } }

![Java:如何将存储为byte []的Class加载到JVM中? Java:如何将存储为byte []的Class加载到JVM中?](http://www.mshxw.com/aiimages/31/486643.png)
