바이트 배열에서 Tomcat에 새로운 클래스 (이전에로드되지 않은)를로드하려고합니다. 또한 Tomcat 응용 프로그램 클래스 로더에 대한 참조도 있습니다. 내가Tomcat에서 새 클래스를 정의하십시오.
Class.forName("com.Class1");
을 다음과 같이 클래스를 확인하려고 할 때 나는
CustomClassLoader customClassLoader = new CustomClassLoader(getClass().getClassLoader());
/*
print getClass().getClassLoader() and it output as
WebappClassLoader
context: /test
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
[email protected]
*/
Class clazz = customClassLoader.loadThisClass("com.Class1");
//print clazz.getMethods, it print my new method.
으로이 클래스 로더를 사용하고
class CustomClassLoader extends ClassLoader{
public CustomClassLoader(ClassLoader classLoader) {
super(classLoader);
}
public Class loadThisClass(String name){
//get .class byte array in data.
Class clazz = defineClass(name, data, 0, data.length, null);
resolveClass(clazz);
return clazz;
}
}
으로 내 사용자 정의 클래스 로더를 선언 나는 ClassNotFoundException가이 클래스를 얻고있다 웹 응용 프로그램의 다른 클래스에서 액세스 할 수 없습니다.
웹 응용 프로그램의 다른 클래스에서 액세스 할 수있는 새 클래스를 tomcat 웹 응용 프로그램에서 정의 할 수 있습니까?.
수업 이름을 확인하셨습니까? ClassLoader의 메소드에 대한 String 매개 변수로 제공된 클래스 이름은 Java ™ 언어 사양 –
에 정의 된대로 2 진 이름이어야합니다. WEB-INF/classes에있는 클래스 파일 이름은 무엇입니까 –