maven打war包出錯解決
在用maven打包時,出現過如下兩個錯誤:
錯誤1:程式包javax.servlet不存在,程式包javax.servlet.http不存在
錯誤2:
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile)。。。
一、錯誤1
出現原因:java編譯器沒有找到軟體包javax.servlet。
解決方法:在pom.xml中新增以下依賴包
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId >javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
待依賴下載完成後,右鍵——>maven——>Update Projects…
有時候jsp頁面也會報錯誤,也是相關javax.servlet.http
找不到,一種方法是採用上述方法,在pom中新增依賴;第二種方法如下:
在專案上右鍵——>Build Path——>Configure Build Path,然後如圖:
依次Next就可以了。
二、錯誤二
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.764 s
[INFO] Finished at: 2018-03-19T15:14:00+08:00
[INFO] Final Memory: 11M/110M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project book-donation: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
1.錯誤原因:eclipse預設選擇jre執行程式,而maven的install要求使用jdk,因此報編譯環境找不到的錯誤。
2.解決方法:將jre改為jdk
3.詳細步驟:
專案右鍵——>Build Path——>Configure Build Path…,開啟視窗後,按照如下圖步驟進行選擇,此步驟是將jre換為jdk
完成後,先更新一下maven專案(右鍵——>maven——>Update Projects…),再clean以下專案(右鍵——>Run As…——>Maven Clean),最後再打包(右鍵——>Run As…——>Maven install)。