See many new MAVEN projects on the Internet, are older, and not clear.
Especially cannot change version of the project Facet Dynamic Web module to 3.0 This problem, some workarounds are not very good.
Let's talk about how to create a new MAVEN project correctly, and why you can't turn it into a Dynamic Web module3.0.
If you are familiar with eclipse, don't say much, please look at the picture:
Enter the web in the filter. We're going to create a new Web project.
The default JDK and compiler for the newly generated project are 1.5. And there is no such directory as Src/main/java. The Web. XML is also 2.3. So the first thing we do is modify Web. xml
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://xmlns.jcp.org/xml/ns/javaee" xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee/http Xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd "id=" webapp_id "version=" 3.1 "><display-name>archetype Created Web application</display-name></web-app>
Then uncheck these two items here and click OK
Open this page again, tick the two items, then click further ocnfiguration available
Remove the default compilation path (the path is incorrect, you must delete it, or you will get an error).
Change to Src/main/java and src/main/resources. Output path changed to Target/classes
At the end of this step, our Src/main/java directory also appears automatically.
That's the way it ends. Click Next
This step does not change into a src/main/webapp. A webcontent directory is generated by default. The contents of the WebContent directory are repeated with WebApp. We can use WebApp.
:
Look at the compilation path again, very good. Is the effect we want.
JDK is also JavaSE-1.8, is the effect we want. Note that the JDK is not the JRE. Don't choose the JRE.
The compiler is also 1.8. Yes, it is.
But when we maven>>update project
Project error. Dynamic Module 3.1 requires Java 1.7 or newer
The JDK becomes the default 1.5 at the beginning. This is because there is no configuration in the Pom.xml.
<plugin><artifactId>maven-compiler-plugin</artifactId><version>3.1</version>< configuration><source>1.8</source><target>1.8</target></configuration></ Plugin>
Then the Maven>>update project error was resolved.
Finally, the encoding format is also set, or there will be Chinese words compiled may error.
The complete pom.xml is as follows:
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelversion >4.0.0</modelVersion> <groupId>net.csdn</groupId> <artifactId>mvn9</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>mvn9 Maven Webapp </name> <url>http://maven.apache.org</url> <properties><project.build.sourceencoding >UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <g Roupid>junit</groupid> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <finalname>mvn9 </finalName> <plugins><plugin><artifactid>maven-compiler-plugin</artifactid><version>3.1</version><configuration>< source>1.8</source><target>1.8</target></configuration></plugin><!--< plugin>--><!--<artifactId>maven-war-plugin</artifactId>--><!--<version>2.4 </version>--><!--</plugin>--></plugins> </build></project>
Finally, take a look at the deployment path with no problem. Very good, is the effect we want.
Such a new MAVEN project will be built and summed up:
1. Cannot change version of the project facet Dynamic Web module to 3.0 appears
The reason is that our web. XML was incorrectly written. Solve the problem from the root.
After 2.maven>>update project, the JDK and compiler become the default 1.5. So you have to configure it in the Pom.xml. Or it will be reported
Dynamic Web Module 3.1 requires Java 1.7 or newer
3.maven compile compile the error when the code is reported. So you have to configure project.build.sourceEncoding in the Pom.xml.
Correct new MAVEN Project 2