Java编译器用maven打war包出错解决办法
作者:雪心玉竹 时间:2022-01-18 06:13:29
在用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 ,将jre换为jdk
步骤完成后,先更新一下maven项目(右键——>maven——>Update Projects…),再clean以下项目(右键——>Run As…
——>Maven Clean),最后再打包(右键——>Run As…——>Maven install)。
来源:http://blog.csdn.net/rongxiang111/article/details/79612491