Java编译器用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 ,将jre换为jdk
步骤完成后,先更新一下maven项目(右键——>maven——>update projects…),再clean以下项目(右键——>run as…
——>maven clean),最后再打包(右键——>run as…——>maven install)。
下一篇: 解决 ajax 跨域