How to run Tomcat 7 using Maven 2 Tomcat plugin?

前端 未结 2 1392
無奈伤痛
無奈伤痛 2020-12-12 20:42

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 Ma

相关标签:
2条回答
  • 2020-12-12 21:25

    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.

    0 讨论(0)
  • 2020-12-12 21:33

    Have you tried the tomcat 7 plugin?

    0 讨论(0)
提交回复
热议问题