Create a web project using the eclipse plugin
First create a Maven Project as shown below
We checked Create a simple project (do not use skeleton)
Packing here chooses the form of war
Since packing is a war package, there is an additional directory of webapp below.
Since our project will be published to tomcat using eclipse, here we need to convert the project into a dynamic web project first
Right-click on our project, select properties and find Project Facets, and click Convert to faceted form... as shown below:
Then check Dynamic Web Module and click ok as shown below: (3.0 is only supported by tomcat7)
Next, observe our project structure and add a web content directory
Although we can publish to tomcat at this time, this does not conform to the structure of maven, we have to make the following modifications
Cut the two directories META-INF and WEB-INF under the WebContent in the above figure directly to the src/main/webapp directory, and delete the WebContent directory, then the current project structure is as follows:
Then we need to modify the release rules, right click on the project and select Deployment Assembly
Select WebContent and remove it. We don't need to publish the test class. The two directory pages of test can be removed.
Then re-specify a web path, click add, select Folder --> next
Find the webapp directory under src, then finish
In the last step, we need to point the current build path to Maven Dependency, click add directly, select Java Build Path Entries and then next
Then click finish to finish
After completion, as shown below:
At this point, a maven-based webapp is established and can be published directly from eclipse to tomcat
补充:我们需要在src/main/webapp/WEB-INF下面创建一个web.xml
导入我们的Spring mvc依赖jar包
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>