나는 기본적인 것을 놓치고 있다는 것을 알고있다. 동적으로 클래스를 컴파일 한 다음 변경 후 다시로드하려고합니다. 다음 코드가 작동합니다. 그러나 두 번 (.java를 변경 한 후) 두 번 호출하면 클래스 정의가 업데이트되지 않습니다. 내가 뭘 놓치고 있니?내 수업이 다시로드되지 않는 이유는 무엇입니까?
File file = new File("/eraseme/Eraseme.java");
File[] files = new File[] {file};
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(files);
CompilationTask task = compiler.getTask(null, fileManager, null, null,null,compilationUnits);
boolean madeIt = task.call(); // works
File classFile = new File("/eraseme/Eraseme.class");
URL url = classFile.toURL();
URL[] urls = new URL[] { url };
ClassLoader cl = new URLClassLoader(urls);
Class cls = cl.loadClass("Eraseme");
TestApi test = (TestApi) cls.newInstance();
System.out.println(test.getVersion());
ClassLoader는 실제로 어떻게 든 사용되지 않습니다. .class에 대해 올바른 파일 이름을 넣지 않더라도 여전히 실행됩니다. –