Matt
Matt

Reputation: 5778

Compiled Java compiler in JAR form?

I have an application which requires compiling a .java file into a .class file within the application. Ideally, I'd like to have a JAR that I could use its api to compile by giving two arguments: the name of the file to be compiled and the directory to store the .class file. My application will use the Java compiler, which will be packaged and shipped with the software.

I actually have a small java compiler like I describe in JAR form, but it only has a subset of what java 7.0 has.

Is the java compiler available in Jar form like this?

Upvotes: 0

Views: 368

Answers (2)

iTech
iTech

Reputation: 18430

Java Compiler API (JSR 199) was created for this purpose, you create a compiler instance like this:

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

Here is a good educational tutorial on Generating Java classes dynamically

and here is a related question with example code

Upvotes: 1

Pascal Belloncle
Pascal Belloncle

Reputation: 11389

the compiler is in tools.jar.

refer to http://docs.oracle.com/javase/6/docs/api/javax/tools/package-summary.html

Upvotes: 3

Related Questions