maven-compiler-plugin 插件配置详解
生活随笔
收集整理的這篇文章主要介紹了
maven-compiler-plugin 插件配置详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近在本地運行老項目時,將老代碼拉下來mvn install發現無法執行。報錯如下:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project ordercenter-facade: Compilation failure [ERROR] Failure executing javac, but could not parse the error: [ERROR] ??�?���?����·���� [ERROR] [ERROR] [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException這種非常詭異的報錯,讓我糾結了好長時間。后來終于發現是因為老項目配置的maven-compiler-plugin插件的一個參數導致的。這里特意記錄一下:
該項目maven-compiler-plugin插件中使用了 <executable>參數,該參數指定使用的javac命令,而我本地又沒有該命令,所以報錯了!!!
這里記錄一下maven-compiler-plugin常用的配置:
<plugin> <!-- 指定maven編譯的jdk版本,如果不指定,maven3默認用jdk 1.5 maven2默認用jdk1.3 --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <!-- 一般而言,target與source是保持一致的,但是,有時候為了讓程序能在其他版本的jdk中運行(對于低版本目標jdk,源代碼中不能使用低版本jdk中不支持的語法),會存在target不同于source的情況 --> <source>1.8</source> <!-- 源代碼使用的JDK版本 --> <target>1.8</target> <!-- 需要生成的目標class文件的編譯版本 --> <encoding>UTF-8</encoding><!-- 字符集編碼 --><skipTests>true</skipTests><!-- 跳過測試 --> <verbose>true</verbose><showWarnings>true</showWarnings> <fork>true</fork><!-- 要使compilerVersion標簽生效,還需要將fork設為true,用于明確表示編譯版本配置的可用 --> <executable><!-- path-to-javac --></executable><!-- 使用指定的javac命令,例如:<executable>${JAVA_1_4_HOME}/bin/javac</executable> --> <compilerVersion>1.3</compilerVersion><!-- 指定插件將使用的編譯器的版本 --> <meminitial>128m</meminitial><!-- 編譯器使用的初始內存 --> <maxmem>512m</maxmem><!-- 編譯器使用的最大內存 --> <compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument><!-- 這個選項用來傳遞編譯器自身不包含但是卻支持的參數選項 --> </configuration> </plugin>maven的默認編譯使用的jdk版本貌似很低,使用maven-compiler-plugin插件可以指定項目源碼的jdk版本,編譯后的jdk版本,以及編碼。
總結
以上是生活随笔為你收集整理的maven-compiler-plugin 插件配置详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何在 IDEA 中创建并部署 Java
- 下一篇: 【转】一些获取数据的网站