【问题标题】:How to run Tomcat 7 using Maven 2 Tomcat plugin?如何使用 Maven 2 Tomcat 插件运行 Tomcat 7?
【发布时间】:2011-12-09 17:04:58
【问题描述】:

我正在使用 Maven 2,并且我有一个外部 Tomcat 7。我想知道如何使用 Maven Tomcat 插件运行 Tomcat 7。

Maven 3 中的 Maven Tomcat 插件是否默认运行 Tomcat 7。

谢谢。

【问题讨论】:

    标签: maven-2 maven tomcat7 maven-tomcat-plugin


    【解决方案1】:

    你试过tomcat 7 plugin吗?

    【讨论】:

    【解决方案2】:

    这对我有用:http://tomcat.apache.org/maven-plugin-2.1/

    使用此插件配置:

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

    并运行

    mvn clean install tomcat7:run
    

    (请注意tomcat7:run,而不是tomcat:run。)

    插件文档在这里:http://tomcat.apache.org/maven-plugin-2.1/tomcat7-maven-plugin/plugin-info.html

    例如,the default value of additionalConfigFilesDir${basedir}/src/main/tomcatconf,所以如果你把你的配置放到这个目录中,它将被用于tomcat7:run

    mvn -X tomcat7:run 打印配置,例如:

    [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
    

    注意warSourceDirectory 指向src(不是target),所以它作为一个通常的动态Web 项目运行,你可以更改你的JSP、HTML,它会立即可见。这就是target/tomcat/webapps 文件夹为空的原因。

    【讨论】:

    • 当我尝试它时,我得到了例外: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 任何想法?
    • 我在这里发布了有关异常的信息:stackoverflow.com/questions/7821622/…
    • 另一个问题是,当我尝试将 tomcat 配置目录更改为:&lt;tomcatConfigurationFilesDirectory&gt; D:\apache-tomcat-7.0.22\conf &lt;/tomcatConfigurationFilesDirectory&gt; 它不起作用,它仍然应用来自 app\target\tomcat 的配置
    • tomcat7:run 非常有帮助。错过了这个事实,想知道为什么它仍在运行 Tomcat 6。
    • 谢谢伙计,我浪费了两天时间来寻找合适的文档来让这个插件工作。你的回答真的很有帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 2019-01-03
    相关资源
    最近更新 更多