如何通过Maven将"-J"选项传递给javac?

Ric*_*ner 9 java javac maven maven-compiler-plugin

我有一个使用Maven构建的Java项目.我想在"javac"命令行中添加选项 - 特别是,我想传递一些"-J"选项.

通常我会做这样的事情:

<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>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试这个时,我得到了表单的错误:

[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
Run Code Online (Sandbox Code Playgroud)

经过仔细研究,似乎maven-compiler-plugin将所有编译器参数写入选项文件,并调用javac,如'javac @optionfile'.根据javac的官方文档http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html:

@argfiles列出选项和源文件的一个或多个文件.这些文件中不允许使用-J选项.

所以看起来maven-compiler-plugin中的选项不起作用 - 它想要使用arg文件,arg文件不能包含我想要的选项.

我也看到了一些使用地图的建议 - 但是当我尝试它时,它有类似的结果.

还有其他选择吗?

rad*_*dai 4

编译器插件允许您指定 jdk 的位置,因此您可以使用如下内容:

<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>
Run Code Online (Sandbox Code Playgroud)

并为其提供一个脚本/bat 文件的路径,该文件会将所有参数以及额外的参数传递给真正的 javac?

编辑-原始问题已在编译器插件 2.4+ 中修复,现在应该可以正常工作,无需我的解决方法