MAVEN is a project management tool that integrates functionality, below describes the configuration of the MAVEN Web project in Eclipse species, and is integrated with Tomcat. After a successful configuration, you can debug like a typical Web project.
I. Conditions of preparation
1, installation download JDK
Here take jdk1.6 as an example
2. Install Eclipse
Download Eclipse IDE for Java EE developers version of Eclipse to eclipse website
http://www.eclipse.org/
3. Installation Tomcat6
4. Install Maven
5. Install Eclipse maven Plugin
Installed here in the manner of online installation, the address is: http://m2eclipse.sonatype.org/sites/m2e
Second, the configuration
1. Configure the JDK installation location in Eclipse, Tomcat installation location, MAVEN installation location, specifying the JDK for Tomcat
Not in detail here
2. Create a new MAVEN project in Eclipse
2-1. Create a new MAVEN project, choose Create a simple project ...
2-2,
Click Next to go to the next
Under this window fill in the Group Id,artifact ID, you can write a random, select the war type in packaging
Click Next to continue next in the following steps until the final click Finish
2-3,
Right-click the item, select Properites, and open the following dialog box
In the right navigation bar of this interface, select Project Facets, click the hyperlink convert faceted from, and go to the following interface
2-4,
Select Custom in Configuration
Select version 2.5 in the dynamic WEB module of project facet below
Select 1.6 in Java
Note: These choices may vary according to the Tomcat version, and for Tomcat6 it is OK to choose the above options
This step is very important, only if you operate this step, the right-hand navigation bar will have deployment Assembly links
2-5
Next click on the runtime panel on the right panel
You can see Tomcat in the bottom, if not, click New below, create a new one, select the checkbox after new, and then Apply,ok
2-6,
In the Project Properties panel, select the Deployment Assembly option in the navigation bar on the right side of the Web deployment Assembly
If you see the following diagram, the configuration is complete
This explains the folder above
Src/main/java
This folder is stored in Java source code, the release of the project will be under the folder of the class file to the Web-inf/classes directory
Src/main/resources
This folder generally places the configuration file, such as Xml,properties file, you can also place the Java file, just a convention, the release of the project
The folder's files are also copied into the Web-inf/class
As for test, some are similar, except that these are test code, and the MAVEN should know that.
Src/main/webapp
The MAVEN convention is to take this folder as the Webroot directory in a regular Web project, and look at the deploy path to the right, when publishing the project
is published to the root directory/. This 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 can also run the project, debug the project, but 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 regular Web project, your configuration (pictured above)
No configuration, it will be an error.
What to do, 2 steps.
1, check webcontent,remove off it
2, create a new, source folder for Src/main/webapp,deploy path for/
Click Apply,ok.
Finally, the MAVEN library must be mapped to Web-inf/lib, as follows, click the Add button and go to the following image
Select Java Build Path entries, click Next, and go to the following image
Select Maven dependencies, click Finish, and end with the following figure
If you do not map maven dependencies to Web-inf/lib, you are prompted to not find the class when you use the library in Maven in the service side, such as the 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-click on the Tomcat server, select Add and Remove, and add the new Web project as shown below
Create a servlet in the Src/main/java and create a JSP in the Src/main/webapp
Start Tomcat, visit your servlet and JSP, you can set breakpoints in the servlet, you can debug.