How to run Tomcat 7 using Maven 2 Tomcat plugin?
Asked Answered
B

2

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.

Buddy answered 18/10, 2011 at 0:26 Comment(0)
M
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.

Mate answered 18/10, 2011 at 17:42 Comment(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 ?Buddy
i posted about the exception here: #7822122Buddy
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\tomcatBuddy
do i have to configure the war directory, meaning the place to deploy war file to, coz the folder myapp\target\tomcat\webapps doesn't contain anything, so that when i try to open http:localhost:8080\ i got exceptions from url rewrite framework that there's no classes hereBuddy
well i used mvn clean and then mvn tomcat7:run and everything works fine, and i have no idea how it's workingBuddy
that tomcat7:run was very helpful. Had missed that fact and wondered why it still was running Tomcat 6.Assurance
Thanks mate, I wasted two days to find a proper documentation to get this plugin working. Your answer really helpedAzevedo
The method started the tomcat smoothly but soon I get "xxxx.servlet cannot be cast to javax.servlet.Servlet", have no idea why.Parma
@ChenLin: You should ask it as a separate question (with more context info).Mate
N
2

Have you tried the tomcat 7 plugin?

Notify answered 18/10, 2011 at 0:32 Comment(1)
i tried it, but it gives me an exception: #7805964Buddy

© 2022 - 2024 — McMap. All rights reserved.