在使用maven新建的web项目中,执行
执行如上的这两个操作,报错:
1 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project bioligyInfo: Fatal error compiling: tools.jar not found: C:\Program Files\Java\jre1.8.0_73\..\lib\tools.jar -> [Help 1] 2 [ERROR] 3 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 4 [ERROR] Re-run Maven using the -X switch to enable full debug logging. 5 [ERROR] 6 [ERROR] For more information about the errors and possible solutions, please read the following articles: 7 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 8 9 10 11 12 13 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project bioligyInfo: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1] 14 [ERROR] 15 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 16 [ERROR] Re-run Maven using the -X switch to enable full debug logging. 17 [ERROR] 18 [ERROR] For more information about the errors and possible solutions, please read the following articles: 19 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
上面的两种错误,提示的很明显:
错误1:
其实不用从maven下载插件,只需要保证你的pom.xml文件中有如下的信息即可:
1 <build> 2 <plugins> 3 <plugin> 4 <artifactId>maven-war-plugin</artifactId> 5 <configuration> 6 <version>2.5</version> 7 </configuration> 8 </plugin> 9 </plugins> 10 </build> 11 12 <properties> 13 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 14 <spring.version>4.1.4.RELEASE</spring.version> 15 <hibernate.version>4.3.8.Final</hibernate.version> 16 <jackson.version>2.5.0</jackson.version> 17 18 </properties>
错误2:
提示找不到web.xml文件
解决方法:
1》如果你没有配置web.xml文件,那就创建web.xml文件
2》如果你配置了web.xml文件,还有这样的错误,那就是你的web.xml文件不能被你项目读取到
如下,项目中web.xml的位置如下:
而我们需要让项目读取到它:
因为web.xml文件的路径如下:src\main\webapp\WEB-INF\web.xml
如果依旧无法解决,那就在pom.xml文件中配置如下:
1 <build> 2 <plugins> 3 <plugin> 4 <artifactId>maven-war-plugin</artifactId> 5 <configuration> 6 <version>2.5</version> 7 <webXml>src\main\webapp\WEB-INF\web.xml</webXml> 8 </configuration> 9 </plugin> 10 </plugins> 11 </build>
这样指定到具体的文件上 就可以解决这问题了。