Eclipse creates a Maven-Web project and solves the problem of jre version and web.xml version

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.xmlfile 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.xmlthe 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

write picture description here

choosemaven-archetype-webapp

write picture description here

Group IdIt 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 IdIt is the unique identifier of the project, and the name of the actual corresponding project is the name of the project root directory.

write picture description here

The new Maven project structure is:

write picture description here

Pay attention to the structure of the red box, there is only one src/main/resources, and the project reports the following HttpServlet error

write picture description here

Right-click on the Propertiesproject and Java Build Pathselect Add LibraryAdd and Server Runtimeselect Apache Tomcat7Server (Tomcat8 requires web version 3.1)

write picture description here

HttpServlet bug resolved, project structure also changed, autocompletion src/main/javaand src/test/javadirectories

write picture description here

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 Pathmodify it again, once the project update projectwill 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 Projectproject Java Build Pathas:

write picture description here

Then you can Edit to assign the jre toWorkspace default JRE

write picture description here

2.2 Modify the web.xmlfile 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 Propertiesselect Project Facets(project template), as shown in the figure below, you can see that Dynamic Web Modulethe version is 2.3

write picture description here

Change directly to 3.0? , but cannot change

write picture description here

Here you can Dynamic Web Moduleremove the check first , and then Apply.

write picture description here

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...

write picture description here

After that, modify Content directorit to src/main/webapp, check Generate web.xml deployment descriptorOK, save and exitProject Facets

write picture description here

After modifying the src/main/webapp/WEB-INF/web.xmlfile, 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:

write picture description here

 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326447029&siteId=291194637