Maven 3 getting started-how to create a web application

Source: Internet
Author: User
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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.