2

I've been deving an IDE for Java, Assembly and JMM for the last two months, and have been able to have the JMM compiler to run through the IDE and compile the given code. For some reason, I cannot seem to find a way to do this with Java code. Is there any API call I can use to compile a given class or even somehow invoke javac and give it the necessary values through the command line?

Any help would be greatly appreciated!

The IDE:

enter image description here

Mark Nutt
  • 328
  • 1
  • 3
  • 13
  • `Runtime.exec()` with `javac` should do the trick, if the class is in a file. – MightyPork Aug 05 '13 at 19:56
  • See [Java Compiler API](http://openjdk.java.net/groups/compiler/guide/compilerAPI.html) in javax.tools (ships after Java 1.6 nad later). [Example (see accepted answer)](http://stackoverflow.com/questions/12173294/compiling-fully-in-memory-with-javax-tools-javacompiler) – c.s. Aug 05 '13 at 20:03

2 Answers2

0

You can use the JavaCompiler.

Katona
  • 4,507
  • 19
  • 25
0

You can use a combination of a URLClassLoader to load the source code of the class and a JavaCompiler to compile it.

Contrived example: URLClassLoader and accessibility of package-private methods

Community
  • 1
  • 1
assylias
  • 297,541
  • 71
  • 621
  • 741