How to pass -X program options to java compiler

JavaCompiler - How do I pass -X options programmatically to a JavaCompiler class?

+4
source share
2 answers

There are some nice examples on the JavaCompiler page you're linked to. They invoke the compiler with the following line of code:

 compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call(); 

The fourth argument to the getTask method is a list of parameter strings (indeed Iterable<String> , but the list will suffice). So you can do:

 compiler.getTask(null, fileManager, null, Arrays.asList("-Xlint:all"), null, compilationUnits1).call(); 
+1
source

AFAIK The Java compiler runs in the current JVM. If you want to set the -X option, you need to set it for your program.

0
source

All Articles