javaruntimetools.jar

Java compiler at Runtime


In my current project, I need to compile java code at runtime (in the background to process input from the user). This works fine with tools.jar in the classpath. However, not all users of my program have JDK installed on their system. Some of them only have JRE and in that case there is no java compiler available at runtime. I can solve that problem by including tools.jar from Sun as a part of my tool.

But tools.jar is very big (>12 MB). The problem is that I have to include the large jar file, although I am interested only in a small fraction of the functionality provided by this jar.

  1. Is it possible to break up the tools.jar file so that I have a small subset of classes that are required for compiling java code only?

  2. Is this illegal?

Thanks a lot.


Solution

  • The Eclipse compiler is only 1.6 MB and should work without Eclipse. You can download it here. Also it looks like it implements the JavaCompiler API.

    It is licensed under the Eclipse public license so including it in your own application should be no problem.