Eclipse uses the Maven plugin (M2E) to configure and run Web projects

Source: Internet
Author: User

MAVEN is a project management tool that makes it easy to manage projects. This article describes how to configure a Web project with maven under the eclipse environment and run and debug it under the Tomcat container.

First, the Environment preparation:

1, download tomcat, can download from Apache official online, this article does not repeat.

2, download eclipse, do Java development necessary IDE, also do not repeat.

3, download Mave, can download from http://maven.apache.org/download.cgi.

4, download m3e, this is the official plug-in integrated with Eclipse, can be downloaded from http://wiki.eclipse.org/M2E_updatesite_and_gittags. A section from MAVEN's official website is about the integration of Maven with Eclipse, where the download portal is available.

The installation of the software is not in the scope of this article, readers can obtain the corresponding information from the official website.

Second, the configuration

1. Before use, JDK and Tomcat should be configured in Eclipse.

2, after installing M2E plug-in, configure the Mave

2.1 Tick in Window-preferences-maven, refer to

2.2 In Window-preferences-maven-user settings settings, select the native Maven configuration file.

2.3 Setting in window-preferences-maven-installations (optional)

3. Build a Web Project

3.1 Create a new MAVEN project

3.2 Click Next

3.3 Select the default workspace and click Next

3.4 Because you are creating a Web project, select Maven-archetype-webapp. Click Next.

3.5 Fill out the group Id,artifact id,version and select Finish to create the project. The directory structure is as shown.

4. Configuration Item Properties

4.1 Right click on the project, select Properties-project Facets, click on the right panel of convert to faceted from ...

4.2 Because it is a Web project, you need to tick the dynamic web Module, where the version defaults to 3.0 and needs to be changed to 2.5. Underneath the panel there is a further configuration available ... option, which is primarily to set the context directory of the Web project. The default is WebContent.

Note that in order to avoid creating the default WebContent directory, you can choose further configuration available ... to set the root directory. MAVEN creates Src/main/webapp by default, which corresponds to the root of the Web project, so you can set the following settings so that you avoid establishing the WebContent directory:

Also, select the Runtimes tab on the right side of the panel to set it up, if you have already configured Tomcat, simply select the Web container here, or you will need to recreate it.

4.3 Click OK, the project will be turned into a Web project, the directory structure under the Java perspective is

In the SRC directory, the Src/main/webapp directory already exists, which is the root directory of the Web project. Therefore, the WebContent directory is redundant and can be deleted directly.

4.4 Right-click on the project, select Properties-deployment Assembly, configure the directory structure and the directory of the Java EE application to correspond. As the default mapping relationship:

Note: If the root directory is set up in 4.2 steps, there is no need to configure it here:

4.5 in order to correspond with the root directory of the Java EE, you need to add the directory Src/main/webapp to the root directory/, and in order to use the Lib configured in Maven, the Maven dependency needs to be mapped to Web-inf/lib, as follows:


After the above steps, you can run the project directly from Eclipse in Tomcat. Of course, you can also debug the project.




Eclipse uses the Maven plugin (M2E) to configure and run Web projects

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.