【问题标题】:How to run tomcat from maven?如何从maven运行tomcat?
【发布时间】:2016-07-18 08:15:19
【问题描述】:

有 2 个插件 tomcat7-maven-pluginmaven-t7-plugin 都有很多目标,但它们都构建战争并“即时”运行 tomcat,而我需要从文件夹运行 tomcat。例如。已经下载了需要运行的tomcat。有没有办法简单地运行它而无需构建战争、下载 tomcat 等?

question 没有提供答案,因为它下载了一个 tomcat,将战争放入其中,而需要运行已经存在的 tomcat 而不构建战争并再次下载 tomcat。可能有一种方法可以为该插件配置 tomcat 文件夹吗?但我没有found 任何属性。

【问题讨论】:

标签: java maven tomcat7


【解决方案1】:

你可以试试 maven-exec-plugin

<plugin>  
    <groupId>org.codehaus.mojo</groupId>  
    <artifactId>exec-maven-plugin</artifactId>  
    <version>1.1</version>  
    <executions>  
      <execution>  
        <id>stop-tomcat</id>  
        <phase>pre-clean</phase>  
        <goals>  
          <goal>exec</goal>  
        </goals>  
        <configuration>  
        <executable>${tomcat.stop.path}</executable>  
        </configuration>  
      </execution>  
      <execution>  
        <id>start-tomcat</id>  
        <phase>deploy</phase>  
        <goals>  
          <goal>exec</goal>  
        </goals>  
        <configuration>  
        <executable>${tomcat.start.path}</executable>    
        </configuration>  
      </execution>  
    </executions>  
  </plugin>  

【讨论】:

    【解决方案2】:

    tomcat7-maven-plugin 不是为了那个目的。

    如果您希望在构建时运行普通的 tomcat 实例...您只需在构建之前启动它,或者找到其他方式来运行它.. maven-exec 就像提到的那样,可能会这样做

    tomcat7-maven-plugin 将您的构建部署到 tomcat 的测试实例,该测试实例将在测试完成后终止。

    【讨论】:

      【解决方案3】:

      您可以使用 exec-maven-plugin (http://www.mojohaus.org/exec-maven-plugin/index.html) 从 maven 执行命令行。

      【讨论】:

        【解决方案4】:

        使用货物插件

        <plugin>
          <groupId>org.codehaus.cargo</groupId>
          <artifactId>cargo-maven2-plugin</artifactId>
          <version>1.6.6</version>
          <configuration>
            <container>
              <containerId>tomcat7x</containerId>
              <zipUrlInstaller>
                <url>https://archive.apache.org/dist/tomcat/tomcat-7/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.zip</url>
              </zipUrlInstaller>
            </container>
            <configuration>
              <type>standalone</type>
              <properties>
                <cargo.servlet.port>${cargo.servlet.port}</cargo.servlet.port>
                <cargo.jvmargs>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${cargo.debug.address}</cargo.jvmargs>
              </properties>
            </configuration>
          </configuration>
        </plugin>
        

        通过配置文件激活:

        <profile>
            <id>cargo</id>
            <properties>
                <tomcat.version>7.0.42</tomcat.version>
                <cargo.servlet.port>6280</cargo.servlet.port>
                <cargo.debug.address>8000</cargo.debug.address>
            </properties>
            <build>
                <defaultGoal>cargo:run</defaultGoal>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.cargo</groupId>
                        <artifactId>cargo-maven2-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
        

        【讨论】:

          猜你喜欢
          • 2010-10-29
          • 2011-12-09
          • 1970-01-01
          • 2012-10-05
          • 1970-01-01
          • 1970-01-01
          • 2011-07-05
          • 1970-01-01
          相关资源
          最近更新 更多