Original address: http://blog.csdn.net/chuyuqing/article/details/28879477
Create a Web project with the Eclipse plugin to first create a MAVEN project such as
We tick on create a simple project (do not use skeleton)
Here's packing choose the form of the war
Since packing is a war package, there are more WebApp directories below.
Since our project is going to use eclipse to post to Tomcat, here we need to first turn the project into Dynamic Web project
Right-click on our project, select Properties and find Project Facets, and click Convert to faceted form ... Such as:
Then tick the dynamic Web Module and click OK such as: (3 only TOMCAT7 support)
Next, we look at our project structure, and we have one more Web content directory
Although we can publish to Tomcat at this point, but this does not conform to the structure of MAVEN, we have to make the following changes to the webcontent below the two directory Meta-inf, Web-inf directly cut into the Src/main/webapp directory, and delete the WebContent directory, then the current project structure such as:
Then we have to modify the publishing rules, right click on the project, select Deployment Assembly
Choose WebContent, remove it, test class we do not need to publish, the test of the two directory page can be removed
Then re-specify a Web path, click Add, select Folder--〉next
Locate the WebApp directory under SRC, and then finish
In the final step, we will point the current build path to Maven Dependency, click Add directly, choose Java Build path Entries and Next
Then click Finish to finish
After completion such as:
Now a maven-based WebApp is built and can be published directly from Eclipse into Tomcat
Add: We need to create a Web. XML under Src/main/webapp/web-inf
Import our spring MVC dependency jar Package
<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>
Save directly, MAVEN will automatically download the required jar file for us