Maven2 + TOMCAT6 + Eclipse integrated Configuration

Source: Internet
Author: User
Tags object model

Reprint: Http://wenku.baidu.com/view/d64147c676eeaeaad1f330d4.html?re=view

/*
Maven2 + TOMCAT6 + Eclipse integrated Configuration
Configuration of Maven
environment variable m2_home = Maven home Directory
environment variable PATH = Maven Home directory/bin
Apache-maven/conf/setting.xml file
1. Create a new MAVEN local warehouse folder Apache-maven2-repo and join Setting.xml to specify the local warehouse location
<localRepository>e://apache-maven2-repo</localRepository>
2, add <server>, note <id> The user password value corresponds to the specified configuration of tomcat-users.xml under Tomcat\conf
<server>
<id>tomcat6</id>
<username>admin</username>
<password>admin</password>
</server>
Maven Configuration in Eclipse
1, under the Window-preferences-maven
-installtions,add an external maven, which is to specify the MAVEN directory of its own, choose, without the eclipse built-in maven
Illustration 1
2,-user setting, specify the use of the newly configured Setting.xml file
Configuration of Tomcat
Tomcat/conf/tomcat-users.xml file
1. Add <role>,<user>
<role rolename= "Manager-gui"/> <!--note the value of RoleName, TOMCAT6 has a specified 4 rolename values--
<user username= "admin" password= "admin" roles= "Manager-gui"/>
Additional rolename Information
Manager-gui-allows access to the HTML GUI and the status pages
Manager-script-allows access to the text interface and the status pages
Manager-jmx-allows access to the JMX proxy and the status pages
Manager-status-allows access to the status pages only
Tomcat/conf/server.xml file
1, modify <connector>, start port 8088
<connector port= "8088" protocol= "http/1.1"
connectiontimeout= "20000"
Redirectport= "8443"
uriencoding= "UTF-8"/>
Create a new Java MAVEN project
1. New-project-maven Project
Select All catalogs, select Org.apache.maven.archetypes/maven-archetype-webapp
Illustration 3
GroupId:com.maven.test
Artifaceid:mymaven
Package:com.maven.test.mymaven
Illustration 4
The new Java MAVEN project is created well.
2, pom.xml configuration add <plugins>, detailed configuration is as follows
<project
Xmlns= "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/maven-v4_0_0.xsd "
>
<modelVersion>4.0.0</modelVersion>
<groupId>com.maven.test</groupId>
<artifactId>mymaven</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>mymaven Maven webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>mymaven</finalName>
<plugins>
<!--1th--
<plugin>
<!--2nd--
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<update>true</update>
<charset>utf-8</charset>
<!--3rd--
<url>http://localhost:8088/manager/text</url>
<!--4th--
<server>tomcat6</server>
<port>8088</port>
<path>/mymaven</path>
</configuration>
</plugin>
</plugins>
</build>
</project>
1th:
The Pom.xml file is the core of maven (Pom:project Object Model),
The plug-in required for any project can be loaded in the file.
Add the Tomcat-maven intermediate plug-in to start the external TOMCAT6 server,
This plugin can be used according to the following <groupId>/<artifactId>/<version>
Specifies the configuration, the system automatically will project the required plug-in jar package file,
Download it from Maven Repository Center (download to the local Apache-maven2-repo repository you specified earlier).
The plug-ins required for these projects are automatically downloaded from Maven Repository Center.
Because you want to deploy the project under external Tomcat,
So here you need to join the Tomcat-maven plugin and the tomcat configuration <configuration> tags that you want to start.
2nd:
Tomcat-maven plug-in, can be an officer net reference how to write GroupID and Mojo name
http://tomcat.apache.org/maven-plugin-2.0/
3rd:
Official website explanation: Use Http://localhost:8080/manager/text rather than the default Tomcat6 URL
MAVEN is going to use Tomcat Manager, which roughly means specifying the address of the Tomcat manager
If/manager/text is changed to/manager/html,
The information in MAVEN building will print out a text format of 403 pages for unknown reasons.
4th:
With Setting.xml's <server> assigned <id> name: TOMCAT6
3, according to the Pom.xml building
1) Pom.xml Right-click Run as, Maven Clean, before you start the build.
2) manually start Tomcat, double-click Run Tomcat/bin/startup.bat
3) Pom.xml Right-click Run as, Maven build: Goals fill in the package Tomcat6:deploy, then run
The project target folder generates Mymaven.war and the project is published successfully.
Illustration 4
4) Manually turn Tomcat off, double-click Run Tomcat/bin/shutdown.bat
5) again via Tomcat-maven plugin restart Tomcat,pom.xml Right-click Run as, Maven build: In goals fill in Tomcat6:run
6) Browser type Http://localhost:8088/mymaven, see index.jsp page on behalf of Java MAVEN Project instance succeeded.
Build errors you'll encounter when you first play Maven
1, about Tomcat cannot start, prompt socket bind failed port has been occupied situation:
Workaround: You can open the CMD input Netstat-ano to find the PID occupied by the port,
Then to the task Manager to kill the PID corresponding process, if no accident is directly killed Javaw.exe can be resolved
2. Error when Tomcat:deploy:
[INFO]
---------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
---------------------------------------------------------------------
[INFO] Total time:2.797s
[INFO] Finished at:wed Mar 11:24:37 CST 2013
[INFO] Final memory:6m/12m
[INFO]
---------------------------------------------------------------------
[ERROR] Failed to execute goal
Org.apache.maven.lifecycle.LifecycleExecutionException:Failed to
Execute Goal Org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy
(DEFAULT-CLI) on Project Myfirstmaven:cannot invoke Tomcat Manager
Workaround: Note that the specified <url> is correct and that it has been correctly added in Tomcat-users.xml <role>/<user>
3. Why Tomcat is started with 8080 ports instead of the 8088 ports we need Tomcat:
WORKAROUND: Because if you use Tomcat:deploy or Tomcat:run,maven will automatically invoke the Maven self-brought
tomcat-6.0.29 plug-ins, not the tomcat-6.0.36 of the external settings we need, what do we do? Front
During the Maven-setting.xml setup, the emphasis was placed on a place where Tomcat was configured, <id>tomcat6<id>
It needs to be remembered and will be used later. This is the time to try the Maven build in goals
Input Tomcat6:deploy or Tomcat6:run,ok problem solved, the external tomcat6.0.36 was started
Here it comes.
*/

Maven2 + TOMCAT6 + Eclipse integrated Configuration

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.