Compile a Java file ... using a Java program

Is it possible for a program written in Java to compile a file using the JDK compiler (besides using Java to open a command line and throw out the javac command to compile the file)?

+6
source share
3 answers

In Java 6 onwards, there is an API for using the compiler. This may be what you are looking for.

http://www.javabeat.net/2007/04/the-java-6-0-compiler-api/

http://docs.oracle.com/javase/6/docs/api/javax/tools/JavaCompiler.html

Note that you need the JDK to access the compiler. JRE will not be enough. If this is a problem, consider embedding the Eclipse Java compiler in your application.

+12
source
+10
source

The Apache code password library is your friend.

http://commons.apache.org/bcel/

+3
source

Source: https://habr.com/ru/post/923184/


All Articles