G
Guest
Gast
Hi Leute,
ich habe ein Problem mit dem JavaCompiler (API auf Java 6). Ich möchte damit Klassen dynamisch kompilieren.
Scheinbar funktioniert das kompilieren auch, nur kann ich die Klasse danach nicht laden.
Hier ist eine Beispiel-Implementation (Punkt 8.7.5), bei mir sieht es eigentlich genauso aus, aber das Laen der Klasse funktioniert einfach nicht. www.galileocomputing.de/openbook/javainsel6/javainsel_08_007.htm
Dies hier ist das was ich bis jetzt habe, aber bei loadClass bekomme ich eine ClassNotFoundException.
Danke schonmal im Voraus!
Gruß Nova
ich habe ein Problem mit dem JavaCompiler (API auf Java 6). Ich möchte damit Klassen dynamisch kompilieren.
Scheinbar funktioniert das kompilieren auch, nur kann ich die Klasse danach nicht laden.
Hier ist eine Beispiel-Implementation (Punkt 8.7.5), bei mir sieht es eigentlich genauso aus, aber das Laen der Klasse funktioniert einfach nicht. www.galileocomputing.de/openbook/javainsel6/javainsel_08_007.htm
Dies hier ist das was ich bis jetzt habe, aber bei loadClass bekomme ich eine ClassNotFoundException.
Code:
JavaCompiler theCompiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager theManager = theCompiler.getStandardFileManager(null, null, null);
Collection theSources = new ArrayList();
theSources.add(new Compileable("A", "class A { static { System.out.println(\"Java Compiler API\"); } }"));
JavaCompiler.CompilationTask theTask = theCompiler.getTask(null, theManager, null, null, null, theSources);
theTask.call();
try {
theManager.close();
} catch (IOException e) {
e.printStackTrace();
}
CompileResult theCompileResult = new CompileResult();
try {
Class theCompiledClass = Class.forName("A");
theCompileResult.setCompiledClass(theCompiledClass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return theCompileResult;
Danke schonmal im Voraus!
Gruß Nova