44

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.

2 Answers 2

69

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.

9
  • whn i tried it, i got the exception: WARNING: Unable to load class [org.codehaus.classworlds.ConfiguratorAdapter] to check against the @HandlesTypes annotation of one or more ServletContentInitializers. java.lang.ClassNotFoundException: org.codehaus.classworlds.ConfiguratorAdapter any ideas ?
    – fresh_dev
    Oct 19, 2011 at 12:43
  • i posted about the exception here: stackoverflow.com/questions/7821622/…
    – fresh_dev
    Oct 19, 2011 at 12:54
  • another question is that when i tried to change the tomcat configuration directory as : <tomcatConfigurationFilesDirectory> D:\apache-tomcat-7.0.22\conf </tomcatConfigurationFilesDirectory> it doesn't work, it still applies configuration from app\target\tomcat
    – fresh_dev
    Oct 19, 2011 at 13:09
  • 4
    that tomcat7:run was very helpful. Had missed that fact and wondered why it still was running Tomcat 6.
    – philnate
    Oct 4, 2012 at 10:46
  • 1
    Thanks mate, I wasted two days to find a proper documentation to get this plugin working. Your answer really helped
    – Asanka
    Jan 8, 2014 at 13:42
2

Have you tried the tomcat 7 plugin?

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.