Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does javax.tools depend on the JDK?

I want to use JavaCompiler to dynamically create some classes.

I found the source code of the javax.tools package, but there is no implementation; some posts on the internet say 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

like image 513
Brodie Avatar asked Nov 11 '09 09:11

Brodie


1 Answers

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();
like image 108
Stephen Denne Avatar answered Sep 27 '22 20:09

Stephen Denne