Amoy Mall Series--start Web project with maven Tomcat plugin

Source: Internet
Author: User

We learned how to build a Maven project, and this article will teach you how to start Web Engineering with the Tomcat plugin.
We put the service layer and the performance layer of the project are created, at present, actually can run 2, one is the performance layer engineering--taotao-manager-web, a service layer engineering--taotao-manager. This article first look at the performance layer project, it can run independently, how should it run?

Why use the Maven Tomcat plugin to start Web engineering?

If you want to run the presentation layer project, you should configure a MAVEN tomcat plugin in its pom.xml file instead of running on an external tomcat server as we did earlier. Smart classmates might think, why use the Maven Tomcat plugin to start Web engineering? This is because in the Internet project, more than 10 or even good dozens of Web projects, if you follow the traditional way to add Tomcat server to start, then we to avoid port conflicts, each additional Web project to modify three ports, very troublesome. Using the Maven Tomcat plugin to start the project, you can simply change one port, which is obviously a lot easier.

Starting web Engineering with the MAVEN Tomcat plugin

Currently, the content of the Web. xml file in the presentation layer engineering--taotao-manager-web is empty, so we should modify it to copy the following into the Web. xml file.

<?xml version= "1.0" encoding= "UTF-8"?><Web-appXmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance"xmlns="Http://java.sun.com/xml/ns/javaee"xmlns:web="Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemalocation="Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd " id=" webapp_id " version=" 2.5 "> <display-name>taotao-manager-web</  Display-name> <welcome-file-list> <welcome-file>index.jsp</  welcome-file> </welcome-file-list></web-app>     

To facilitate testing, we create a new index.jsp page in the WebApp directory of the Taotao-manager-web project, with the following content:

<%@ page language="Java" contenttype="Text/html; Charset=utf-8 "pageencoding="UTF-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" ><Html><head><meta http-equiv="Content-type" content= "text/html; Charset=utf-8 "><title>insert title here</title></head>< body> <H1>hello taotao!  </h1></body></html>        

I am as follows:

After the preparation is done, we go straight to the subject.
First configure the Maven Tomcat plugin-related content in the Taotao-manager-web project's Pom.xml file as follows:

<!--Configuring the Tomcat plugin--<Build><Plugins><Plugin><Groupid>org.apache.tomcat.maven</groupid> < artifactid>tomcat7-maven-plugin</ artifactid> <configuration> Span class= "Hljs-tag" ><port>8080</ port> <path>/ </path> </ configuration> </plugin> </plugins></ BUILD>             
    • 1

<path>/<path>the meaning is that after the input localhost:端口号 can be directly to the enter code here Project home page, <port>8080</port> the meaning is to specify the Web project Access port number.
Thus, the contents of the entire Pom.xml file of the Taotao-manager-web project are as follows:

<Projectxmlns="http://maven.apache.org/POM/4.0.0"Xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" ><modelversion>4.0.0</Modelversion><Parent><Groupid>com.taotao</Groupid><Artifactid>taotao-parent</Artifactid><Version>0.0.1-snapshot</Version></Parent><Groupid>com.taotao</Groupid><Artifactid>taotao-manager-web</Artifactid><Version>0.0.1-snapshot</Version><Packaging>war</Packaging><Dependencies><!--Spring--<Dependency><Groupid>org.springframework</Groupid><Artifactid>spring-context</Artifactid></Dependency><Dependency><Groupid>org.springframework</Groupid><Artifactid>spring-beans</Artifactid></Dependency><Dependency><Groupid>org.springframework</Groupid><Artifactid>spring-webmvc</Artifactid></Dependency><Dependency><Groupid>org.springframework</Groupid><Artifactid>spring-jdbc</Artifactid></Dependency><Dependency><Groupid>org.springframework</Groupid><Artifactid>spring-aspects</Artifactid></Dependency><Dependency><Groupid>org.springframework</Groupid><Artifactid>spring-jms</Artifactid></Dependency><Dependency><Groupid>org.springframework</Groupid><Artifactid>spring-context-support</Artifactid></Dependency><!--JSP-related<Dependency><Groupid>jstl</Groupid><Artifactid>jstl</Artifactid></Dependency><Dependency><Groupid>javax.servlet</Groupid><Artifactid>servlet-api</Artifactid><scope>provided</Scope></Dependency><Dependency><Groupid>javax.servlet</Groupid><Artifactid>jsp-api</Artifactid><scope>provided</Scope></Dependency></Dependencies><!--Configuring the Tomcat plugin--<Build><Plugins><Plugin><Groupid>org.apache.tomcat.maven</Groupid><artifactid>tomcat7-maven-plugin </artifactid> <configuration > <port>8080</port> <path>/</< Span class= "Hljs-title" >path> </configuration> </plugin> </ plugins> </build></PROJECT>            

I will use clean tomcat7:run the command to start the project, if you want to, you can follow me to do yo!
On the Taotao-manager-web project, right-click →run as→maven Build, as shown in:

In the Goals input box, enter: clean tomcat7:run click "Apply" and "run" to run the Web project.

At this point the Eclipse console prints as follows:

This means that we have successfully started the Web project using the Maven Tomcat plugin and have not made an error. This is really lucky!!!
After the project is started, we enter it in the browser address bar http://localhost:8080 to access the project. You can see the page output "Hello taotao! "That means our Web project has started successfully!"

Last Words

I thought the first time I used the Maven Tomcat plugin to start the Web project would be an error, and I was a little flattered that I didn't expect it to be so smooth. There may also be small partners for the first time not as smooth as I may have encountered a problem--Cannot find taotao-parent this project, and we want to run the Web project relies on Taotao-parent this project. So our web project to run, we must find this dependency, this dependency is not in the Eclipse workspace inside, it to go to the local warehouse to find, because the local warehouse and there is no taotao-parent package, it will naturally find, can not find the error! So we should first install this taotao-parent project to the local warehouse, after installation, and then start. How to install it? Here are the steps:
Right-click on the Taotao-parent project and select "Run as" in the context menu and tap "Maven install" in its submenu, as shown in:

After packing, we can see that there are already taotao related packages in the local Maven repository, as shown in.

Double-click into Taotao and you can see taotao-parent as shown in.

If we meet this problem again, I believe we can solve it.

Amoy Mall Series--start Web project with maven Tomcat plugin

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.