I have a Java project which is built using Maven. I would like to add options to the "javac" command line - particularly, I want to pass a few "-J" options.
So normally I would do something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-J-Xdebug</compilerArgument>
<compilerArgument>-J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005</compilerArgument>
</configuration>
</plugin>
However when I try this I get errors of the form:
[ERROR] Failure executing javac, but could not parse the error:
javac: invalid flag: -J-Xdebug
Usage: javac <options> <source files>
use -help for a list of possible options
On closer investigation, it seems that maven-compiler-plugin writes all the compiler arguments out to an options file, and invokes javac like 'javac @optionfile'. According to the official documentation for javac at http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html:
@argfiles One or more files that lists options and source files. The -J options are not allowed in these files.
So it looks like the option in maven-compiler-plugin is not going to work - it wants to use arg files, arg files cannot contain the options I want.
I've also seen some suggestions to use the map instead - however this had similar results when I tried it.
Are there any other options?
The compiler plugin allows you to specify the location of the jdk, so you could use something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable><!-- path-to-javac-invoking-script --></executable>
<compilerVersion>1.3</compilerVersion>
</configuration>
</plugin>
and provide it with a path to a script/bat file that would pass all the arguments along to the real javac along with your extra arguments?
EDIT - the original issue has been fixed in compiler plugin 2.4+ and this should just work now without my workaround
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With