Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Tomcat 7 using Maven 2 Tomcat plugin?

I am using Maven 2 and I have an external Tomcat 7. I was wondering how to run Tomcat 7 from using Maven Tomcat plugin.

And does Maven Tomcat plugin in Maven 3 runs the Tomcat 7 by default.

Thanks.

like image 347
fresh_dev Avatar asked Oct 18 '11 00: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.

Does Maven use Tomcat?

Yes, this is really possible and is very easy to handle through the use of powerful tool “Maven“. Maven provides a graceful plugin called tomcat7-maven-plugin through which the Tomcat Web Server can be embedded seamlessly into a Maven project.

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

This works for me: http://tomcat.apache.org/maven-plugin-2.1/

With this plugin config:

<plugin>   <groupId>org.apache.tomcat.maven</groupId>   <artifactId>tomcat7-maven-plugin</artifactId>   <version>2.1</version>   <configuration>     <path>/</path>   </configuration> </plugin> 

And running with

mvn clean install tomcat7:run 

(Please note that tomcat7:run, not tomcat:run.)

Plugin documentation is here: http://tomcat.apache.org/maven-plugin-2.1/tomcat7-maven-plugin/plugin-info.html

For example, the default value of additionalConfigFilesDir is ${basedir}/src/main/tomcatconf, so if you put your configs into this directory it will be used on tomcat7:run.

mvn -X tomcat7:run prints the configration, for example:

[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 

Note that 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. That's why the target/tomcat/webapps folder is empty.

like image 79
palacsint Avatar answered Sep 19 '22 06:09

palacsint