Eclipse Configuration Maven Web project deployment assembly

Source: Internet
Author: User
Tags root directory tomcat tomcat server

Original address:

http://zk1878.iteye.com/blog/1222330

MAVEN is a project management tool that combines a variety of functions, the following describes the configuration of the MAVEN Web project in Eclipse, and integrates with Tomcat. After the configuration is successful, you can debug as a typical Web project.

I. Conditions of preparation

1. Install and download JDK

Here take jdk1.6 as an example

2. Install Eclipse

Download Eclipse IDE for Java EE developers version of Eclipse on the Eclipse website

http://www.eclipse.org/

3, Installation Tomcat6

4. Install Maven

5. Install Eclipse maven Plugin

Here to install the way, the installation address is: HTTP://M2ECLIPSE.SONATYPE.ORG/SITES/M2E

Second, the configuration

1. Configure JDK installation location in Eclipse, Tomcat installation location, MAVEN installation location, specify JDK for Tomcat

Not detailed here

2. Create a new MAVEN project in Eclipse

2-1. Create a new MAVEN project and choose Create a simple project ...

2-2.

Click Next to go to the next

In this window, fill in the group Id,artifact ID, you can write a random, select the war type in packaging

Click Next and continue next in the following steps until the last click Finish

2-3.

Right-click the project, select Properites, and open the following dialog box

In the right navigation bar of this interface, select Project Facets, and click the hyperlink convert faceted from to enter the following interface

2-4.

Select Custom in the configuration

Select version 2.5 in the dynamic WEB module of the project facet below

Select 1.6 in Java

Note: These choices may vary depending on the version of Tomcat, and it is possible for TOMCAT6 to select the options above.

This step is very important, only the right navigation bar will have the deployment Assembly link only if you have done this step

2-5

Next click on the runtime panel on the right panel

You can see Tomcat below, and if not, click New, create one, select the check box after new, and then Apply,ok

2-6.

In the Project Properties panel, select the Deployment Assembly option in the Make department navigation bar on the right side of the Web Deployment Assembly

If you see the following illustration, the configuration is completed

Here to explain the above folder

Src/main/java

This folder is stored in Java source code, publish the project will be under the folder of the class file copied to the Web-inf/classes directory

Src/main/resources

This folder generally placed configuration files, such as xml,properties files, etc., can also be placed in Java files, just a convention, when the project was published

Files for this folder are also copied to Web-inf/class

As for test, there are some similarities, but these are testing code, and using Maven should know that.

Src/main/webapp

The contract in Maven is to think of the folder as a Webroot directory in a normal Web project, see the Deploy path on the right, and publish the project

is published to the root directory/. The folder is in the built Maven WEB project, and there are no Web-inf/classes,web-inf/lib folders in it

Need to be built manually

Note: Sometimes for some reason, the above view you open may be the following,

In fact, this is also possible to run the project, debugging the project, however, if you run the project's Pom.xml file will be an error, why,

Because Maven treats the Src/main/webapp file as a webroot in a normal Web project, your configuration (pictured above)

Without configuration, it will be an error.

What to do, 2 steps.

1. Select Webcontent,remove to drop it

2, create a new, the source folder for Src/main/webapp,deploy path is/

Click Apply,ok.

Finally, the MAVEN library must be mapped to Web-inf/lib, as follows, click the Add button to enter the following image

Select Java Build Path entries, click Next to enter the following image

Select Maven Dependencies, click Finish, as shown in the final figure


If you do not map maven dependencies to Web-inf/lib, you will be prompted not to find the class when using a library in Maven, such as a servlet (although you do not have red xx when you write code, but you cannot find the class when you run the program)

Third, the operation

Add your project in Eclipse's server view, right-select the Tomcat server, select Add and Remove, add the new Web project you just created, the effect is as shown below

Create a servlet in Src/main/java and create a JSP in the Src/main/webapp

Start Tomcat, access your servlet and JSP, and in the servlet you can set breakpoints and debug.

Related Article

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.