Deploy the Java project that Maven created to run in Tomcat

Source: Internet
Author: User
Tags tomcat server
1. Add the following Tomcat server configuration in ~/.m2/settings.xml (here's a question: Do you want to configure tomcat-user.xml locally?) There are tutorials on the Internet to configure it.
<servers>
<server>
<id>tomcat6</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
2. Law 1: Configuring in POM
<build>
<finalName>testdemo</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<server>tomcat6</server>
<url>http://localhost:8080/manager</url>
<path>/testdemo</path>
<!--<warFile>${project.build.directory}/testdemo.war</warFile>-->
</configuration>
</plugin>
</plugins>
</build>

On the command line, enter the following command:
A. Switching items sitting in a folder
D:
CD Workspace/testdemo
B. Cleaning up, packing
MVN Clean (only execute mvn clean and no war package will be generated under target)
Or
MVN Clean Install-dmaven.test.skip=true
C. continue to enter commands
MVN Tomcat:run (This is located to the engineering Src/main/webapp directory)
Or

MVN Tomcat:run-war

the Tomcat will be started here
D. Visit to Http://localhost:8080/testdemo
E. Stop Tomcat
CTRL + C

Y


===================================================================================

1. Add the following Tomcat server configuration to the ~/.m2/settings.xml
<servers>
<server>
<id>tomcat6</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
2. Law 1: Configuring in POM
<build>
<finalName>testdemo</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0-beta-1</version>
<configuration>
<server>tomcat6</server>
<url>http://localhost:8080/manager</url>
<path>/testdemo</path>
</configuration>
</plugin>
</plugins>
</build>

On the command line, enter the following command:
A. Switching items sitting in a folder
D:
CD Workspace/testdemo
B. Cleaning up, packing
MVN clean
Or
MVN Clean Install-dmaven.test.skip=true
C. continue to enter commands
MVN Tomcat6:run
Or

MVN Tomcat6:run-war

Or

MVN Tomcat6:start

the Tomcat will be started here
D. Visit to Http://localhost:8080/testdemo
E. Stop Tomcat
CTRL + C

Y

=================================================================

1. Add the following Tomcat server configuration to the ~/.m2/settings.xml
<servers>
<server>
<id>tomcat6</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
2. Law 1: Configuring in POM
<build>
<finalName>testdemo</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0-beta-1</version>
<configuration>
<server>tomcat6</server>
<url>http://localhost:8080/manager/html</url>
<path>/testdemo</path>
</configuration>
</plugin>
</plugins>
</build>


How Eclipse enters breakpoint debugging (provided that Eclipse installs the Maven plug-in, the project is created by Maven, and the TOMCAT6/7 plug-in is configured in the engineering Pom.xml as described above):

1. Project right key--> debugging mode--> Debug Configuration-->maven Build

2. Maven build--> the right side of the new-->: Main-->base directory-->browse workspace--> Select the project to be debugged-->goals:clean Tomcat6:run (if it is TOMCAT7 input: tomcat7:run)-->skip tests--> application--> debugging (during the boot process will be downloaded from the warehouse dependent Plug-ins, attention to the warehouse <repositories > Configuration)

3. Access URL Actions

4. After entering the breakpoint, if the report can not find the source, then click "Edit Source Find Path"--> "Add"-->java project--> determine--> tick to debug project--> determine--> determine--> enter breakpoint


For more TOMCAT6/7 orders, check yourself: http://tomcat.apache.org/maven-plugin-2/context-goals.html


Resources:

http://zhoucl.iteye.com/blog/1164495

Http://tomcat.apache.org/maven-plugin-2.0-SNAPSHOT/tomcat6-maven-plugin/usage.html

Http://tomcat.apache.org/maven-plugin-2/context-goals.html



Added: If the page directory is not webapp configuration <warSourceDirectory> directory </warSourceDirectory>

<build>
<finalName>testPrj</finalName>
<plugins>
<!--Local development and commissioning-->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<warSourceDirectory>WebRoot</warSourceDirectory>
<scanIntervalSeconds>10</scanIntervalSeconds>
<url>http://localhost:8080/manager</url>
<path>/testPrj</path>
<port>8080</port>
<uriEncoding>GBK</uriEncoding>
</configuration>
</plugin>
</plugins>
</build>


To play the war package, copy the jar package under Web-inf/lib:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warName>${project.artifactId}</warName>
<warName>testPrj</warName>
<webResources>
<resource>
<directory>lib/</directory>
<targetPath>WEB-INF/lib</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>

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.