maven-compiler-plugin 插件配置详解
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                maven-compiler-plugin 插件配置详解
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                最近在本地運(yùn)行老項(xiàng)目時(shí),將老代碼拉下來mvn install發(fā)現(xiàn)無法執(zhí)行。報(bào)錯(cuò)如下:
[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這種非常詭異的報(bào)錯(cuò),讓我糾結(jié)了好長時(shí)間。后來終于發(fā)現(xiàn)是因?yàn)槔享?xiàng)目配置的maven-compiler-plugin插件的一個(gè)參數(shù)導(dǎo)致的。這里特意記錄一下:
該項(xiàng)目maven-compiler-plugin插件中使用了 <executable>參數(shù),該參數(shù)指定使用的javac命令,而我本地又沒有該命令,所以報(bào)錯(cuò)了!!!
這里記錄一下maven-compiler-plugin常用的配置:
<plugin> <!-- 指定maven編譯的jdk版本,如果不指定,maven3默認(rèn)用jdk 1.5 maven2默認(rèn)用jdk1.3 --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <!-- 一般而言,target與source是保持一致的,但是,有時(shí)候?yàn)榱俗尦绦蚰茉谄渌姹镜膉dk中運(yùn)行(對(duì)于低版本目標(biāo)jdk,源代碼中不能使用低版本jdk中不支持的語法),會(huì)存在target不同于source的情況 --> <source>1.8</source> <!-- 源代碼使用的JDK版本 --> <target>1.8</target> <!-- 需要生成的目標(biāo)class文件的編譯版本 --> <encoding>UTF-8</encoding><!-- 字符集編碼 --><skipTests>true</skipTests><!-- 跳過測試 --> <verbose>true</verbose><showWarnings>true</showWarnings> <fork>true</fork><!-- 要使compilerVersion標(biāo)簽生效,還需要將fork設(shè)為true,用于明確表示編譯版本配置的可用 --> <executable><!-- path-to-javac --></executable><!-- 使用指定的javac命令,例如:<executable>${JAVA_1_4_HOME}/bin/javac</executable> --> <compilerVersion>1.3</compilerVersion><!-- 指定插件將使用的編譯器的版本 --> <meminitial>128m</meminitial><!-- 編譯器使用的初始內(nèi)存 --> <maxmem>512m</maxmem><!-- 編譯器使用的最大內(nèi)存 --> <compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument><!-- 這個(gè)選項(xiàng)用來傳遞編譯器自身不包含但是卻支持的參數(shù)選項(xiàng) --> </configuration> </plugin>maven的默認(rèn)編譯使用的jdk版本貌似很低,使用maven-compiler-plugin插件可以指定項(xiàng)目源碼的jdk版本,編譯后的jdk版本,以及編碼。
總結(jié)
以上是生活随笔為你收集整理的maven-compiler-plugin 插件配置详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 如何在 IDEA 中创建并部署 Java
- 下一篇: 【转】一些获取数据的网站
