1. 程式人生 > >Maven中source外掛的使用及其注意問題

Maven中source外掛的使用及其注意問題

               

       使用source外掛,可以使我們在package打包過程中也打包專案原始碼。使用source外掛,需要我們在 pom.xml 中新增配置:

<span style="font-size:18px;"><build>   <!-- 打包原始碼的外掛 -->   <plugins>    <plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-source-plugin</artifactId
>
     <version>2.4</version>          <!-- 進行package命令時就可以將原始碼同時進行打包 -->     <!-- 所以我們需要繫結source外掛到我們default生命週期的package階段 -->     <executions>      <execution>       <!-- 定義一個階段,這個階段是package -->       <phase>package</phase>       <goals>        <goal
>
jar-no-fork</goal>       </goals>      </execution>     </executions>    </plugin>   </plugins>  </build></span>

       新增配置後,在eclipse中 對 pom.xnl 右鍵,選擇 Run as -> Maven build...

       在 Goals 中輸入 clean package,點選Run後可能會出現如下錯誤:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project hi: Fatal error compiling: tools.jar not found: F:\Program Files\Java\jre8\..\lib\tools.jar -> [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/MojoExecutionException


       解決方式:

選擇選單中 Window -> Preferences

選擇 Add...

點選 Next,然後選擇 JDK 所在目錄路徑,點選完成:

勾選剛建立的JRE目錄,點選OK:

再次執行 clean package 命令:

成功執行,並且成功打包出項目原始碼。如下: