views:

115

answers:

1

hi, i want to use JavaCompiler to dynamic create some classes. i find the source code of javax.tools package, but there is no implementation, some posts on internet says it depends on tools.jar, i am not sure tools.jar associates with JRE.

so can i run the program in a JRE environment without JDK installed?

another question, what is the implementation detail of JavaCompiler, is it creating a new process to invoke the javac command?

thanks

+3  A: 

JRE's need to include the interfaces, and classes in that package, but do not need to provide implementations.

Sun's JRE doesn't, and returns null from calling ToolProvider.getSystemJavaCompiler().

This other question addresses java 5.

Here's a blog post by Morten Nobel-Jørgensen on how to use eclipse's compiler as an implementation of javax.tools.JavaCompiler.

JavaCompiler javac = new EclipseCompiler();
Stephen Denne
thank you, i already finished the coding, but if the getSystemJavaCompiler() returns null, the program would fail. so i need to avoid it
Brodie