eclipse creates maven web project

1. Create a new maven project, File → New → Other..., select Maven Project

  

2. Click Next to configure the project workspace and the group to which it belongs (you can not modify it, the default is OK)

  

3. Click Next and select maven-archetype-webapp

  

4. Click Next, fill in the Group id and Artifact id, the Version is the default, and the Package will be automatically generated according to the Group id and Artifact id, you can leave it unchanged

  

5. Click Finish and see that the created project directory looks like this

  

6. Select the project, right-click New →  Source Folder  to create three folders: src/main/java, src/test/java, and src/test/resources

At this step, there may be such a situation, indicating that the folder exists, but we can't see it

  

7. Right-click the project, Properties (or Build Path → Configure Build Path)

  

8. Select JRE...J2SE-1.5 → Edit (or select JRE...J2SE-1.5 → Remove → Add Library... → JRE System Library → Next), switch JRE to the default workspace

  

 

9. Click Finish, and then click Apply and OK on the Properties pop-up window in turn. The existing but invisible folders in step 6 will be displayed. No error was reported when src/test/resources was created in step 6, and it was normal. create

  

10. When creating a new project, select maven-artchetype-webapp. This catalog is relatively old, and the servlet used is still 2.3. We can switch Dynamic.... from 2.3 to 3.0, and Java from 1.5 to 1.8

  

Replacing the version directly will report an error

  

Steps to resolve the above error:

1 、 、 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>

changed to

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 
<display-name>Archetype Created Web Application</display-name>
</web-app> 

2), org.eclipse.jdt.core.prefs under study project.settings

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5

changed to

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

 3)、org.eclipse.wst.common.project.facet.core.xml

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="jst.web" version="2.3"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
  <installed facet="java" version="1.5"/>
</faceted-project>

changed to

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="jst.web" version="3.0"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
  <installed facet="java" version="1.8"/>
</faceted-project>

4), refresh the project, and then reopen the property project Facets

  

11. Add tomcat configuration to the build tag of pom.xml

<plugins>
        <!-- Config: Maven Tomcat Plugin -->
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
        </plugin>
</plugins>

12. Run the project Run As → Maven Build, Goals configure the port as shown below, click Run

  

14. Open the browser and enter: http://localhost:8080/study

There is no problem with the test, the above is the maven web project construction~

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

 

Guess you like

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