Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mvn tomcat7:run - How does it work?

I just want to understand, because I got the code from another question, and it's working fine, but I don't understand the flow of this operation.

This is my understanding of Apache Maven Tomcat plugin for Tomcat 7, when using mvn tomcat7:run with following configuration:

<plugin>     <groupId>org.apache.tomcat.maven</groupId>     <artifactId>tomcat7-maven-plugin</artifactId>     <version>2.0-SNAPSHOT</version>     <configuration>         <path>/${project.build.finalName}</path>     </configuration> </plugin> 

It creates a new Tomcat 7 instance with default configuration, then use project war file as a deployed project in this instance, am I right, please correct me if I am wrong, or someone please describe to me how this process is working, thanks in advance.

like image 587
fresh_dev Avatar asked Oct 19 '11 14:10

fresh_dev


People also ask

What is tomcat7 Maven plugin?

The Tomcat7 Maven Plugin provides goals to manipulate WAR projects within the Tomcat servlet container version 7.x.

How do I run a Maven project from Tomcat in Eclipse?

Right-click the maven project, click Run As —> Run Configurations menu item. Input clean install tomcat7:deploy in the Goals input text box deploy maven project to tomcat. Click Run button, when you see BUILD SUCCESS in the output console, that means the maven deploy to tomcat server process complete successfully.


1 Answers

pom.xml of the tomcat7-maven-plugin depends on Tomcat's bundles. Maven download them and the plugin starts an embedded Tomcat instance with the webproject.

mvn -X tomcat7:run prints the configuration. Some interesting parts:

[INFO] Preparing tomcat7:run [DEBUG] (s) resources = [Resource {targetPath: null, filtering: false,      FileSet {directory: /workspace/webtest1/src/main/resources,      PatternSet [includes: {}, excludes: {}]}}] ... [DEBUG] (f) additionalConfigFilesDir = /workspace/webtest1/src/main/tomcatconf [DEBUG] (f) configurationDir = /workspace/webtest1/target/tomcat ... [DEBUG] (f) path = /webtest1 ... [DEBUG] (f) port = 8080 [DEBUG] (f) project = ...:webtest1:0.0.1-SNAPSHOT @ /workspace/webtest1/pom.xml ... [DEBUG] (f) warSourceDirectory = /workspace/webtest1/src/main/webapp ... [INFO] Creating Tomcat server configuration at /workspace/webtest1/target/tomcat ... [DEBUG] adding classPathElementFile file:/workspace/webtest1/target/classes/ [DEBUG] add dependency to webapploader org.slf4j:slf4j-api:1.5.6:compile ... 

warSourceDirectory points to src (not target), so it runs as an usual dynamic web project, you could change your JSPs, HTMLs and it will visible immediately. Because of that the target/tomcat/webapps folder is empty.

The site of v1.2 contains a more detailed documentation than the site of 2.0-SNAPSHOT about configuration: http://mojo.codehaus.org/tomcat-maven-plugin/plugin-info.html.

like image 140
palacsint Avatar answered Sep 22 '22 17:09

palacsint