http://blog.csdn.net/peng_hong_fu/article/details/53584104
Eclipse creates a Maven-Web project and solves the problem of jre version and web.xml version
When Eclipse creates an SSM framework project (web project) through Maven, the default web.xml
file version is 2.3 and the jre version is 1.5; various problems were encountered when modifying its version,
such as :
web.xml is missing and <failOnMissingWebXml> is set to true
JavaServer Faces 2.2 can not be installed : One or more constraints have not been satisfied.
JavaServer Faces 2.2 requires Dynamic Web Module 2.5 or newer
等问题
The wrong configuration order when looking up methods is also the cause of the problem. Modify jre and web.xml versions, to deal with the relationship between versions, such as web3.0 requires Java 1.6 or above, JavaServer Faces requires web version 2.5 or above, etc.; understanding the rules, you can solve the problem well.
The following is a summary of a method that has the entire flow of creation.
In addition: a feasible method is by modifying
.settings/org.eclipse.wst.common.project.facet.core.xml
the web and Java versions in the files in the project directory. The following method does not need to modify this file and is more convenient.
Eclipse version:Neon.1a Release (4.6.1)
1. Create a new Maven Project
chooseMaven Project
choosemaven-archetype-webapp
Group Id
It is the unique identifier of the project organization, which actually corresponds to the structure of the Java package, which is the directory structure of java in the main directory. Artifact Id
It is the unique identifier of the project, and the name of the actual corresponding project is the name of the project root directory.
The new Maven project structure is:
Pay attention to the structure of the red box, there is only one src/main/resources, and the project reports the following HttpServlet error
Right-click on the Properties
project and Java Build Path
select Add Library
Add and Server Runtime
select Apache Tomcat7
Server (Tomcat8 requires web version 3.1)
HttpServlet bug resolved, project structure also changed, autocompletion src/main/java
and src/test/java
directories
At this moment, the web.xml version of the maven project is 2.3, and the jre version is 1.5, which needs to be upgraded.
2. Modify the project jre version and web.xml version
There are many and complicated versions on the Internet, and your own practice is the key
2.1 Modify jre version
Modify the jre version, you can't Java Bulid Path
modify it again, once the project update project
will return to version 1.5, you can declare it in the pom.xml file
pom.xml
...
<build>
<finalName>TestMaven3</finalName>
<plugins>
<!-- 修改maven默认的JRE编译版本,1.8代表JRE编译的版本,根据自己的安装版本选择1.7或1.8 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Right-click on the project and select the Maven Update Project
project Java Build Path
as:
Then you can Edit to assign the jre toWorkspace default JRE
2.2 Modify the web.xml
file version
This is generated by default web.xml
, and you can see that it is version 2.3.
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
Right-click on the project and Properties
select Project Facets
(project template), as shown in the figure below, you can see that Dynamic Web Module
the version is 2.3
Change directly to 3.0? , but cannot change
Here you can Dynamic Web Module
remove the check first , and then Apply.
Then checkDynamic Web Module
it again , pay attention to the Further configuration available...
options below; then change to the desired version 3.0, clickFurther configuration available...
After that, modify Content director
it to src/main/webapp
, check Generate web.xml deployment descriptor
OK, save and exitProject Facets
After modifying the src/main/webapp/WEB-INF/web.xml
file, the header information version is modified to version 3.0.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
</web-app>
After that, right click on the project and select Maven Update Project
.
The project structure is: