Use the Eclipse plug-in to create a web project. First, create a Maven project, as shown in figure
Select create a simple project (no skeleton is used)
Here, packing is in the war format.
Since packing is a war package, the webapp directory is displayed below.
Because our project needs to be released to Tomcat using eclipse, we need to first convert the project into a dynamic web project
Right-click our project, select Properties, find project facets, and click convert to faceted form... For example:
Check the dynamic Web module and click OK, as shown in figure (3.0 only tomcat7 is supported)
Next, observe our project structure and add a Web content directory.
Although at this point we can release to Tomcat, but this does not conform to the maven structure, we also need to make the following modifications to the webcontent under the two directory META-INF, WEB-INF directly cut to src/main/webapp directory, and delete the webcontent directory. The current project structure is as follows:
Then we need to modify the publishing rule, right-click the project, and select deployment assembly.
Select webcontent and remove it. We do not need to release the test class. The two directory pages of test can be removed.
Specify a new web path, click Add, and select folder --> next
Find the webapp directory under SRC, and then finish
In the last step, we need to direct the current build path to Maven dependency, click Add, select Java build path entries, and next
Then click Finish.
After completion, such:
So far, a Maven-based webapp has been created and can be released directly from eclipse to Tomcat.
Add: we need to create a web. xml under src/main/webapp/WEB-INF
Import our spring MVC dependent 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