![JAR search and dependency download from the Maven repository](/logo.png)
org.mdkt.compiler.DynamicClassLoader Maven / Gradle / Ivy
package org.mdkt.compiler;
import java.util.HashMap;
import java.util.Map;
/**
* Created by trung on 5/3/15.
*/
public class DynamicClassLoader extends ClassLoader {
private Map customCompiledCode = new HashMap<>();
public DynamicClassLoader(ClassLoader parent) {
super(parent);
}
public void setCode(CompiledCode cc) {
customCompiledCode.put(cc.getName(), cc);
}
@Override
protected Class> findClass(String name) throws ClassNotFoundException {
CompiledCode cc = customCompiledCode.get(name);
if (cc == null) {
return super.findClass(name);
}
byte[] byteCode = cc.getByteCode();
return defineClass(name, byteCode, 0, byteCode.length);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy