【问题标题】:Using "provided" classpath in tomcat7-maven-plugin goals在 tomcat7-maven-plugin 目标中使用“提供的”类路径
【发布时间】:2013-06-29 21:49:01
【问题描述】:

我的 webapp 中有一些依赖项已标记为 provided,因为我希望它们由应用服务器提供(可能生产环境在指定版本提供这些依赖项)。当我在本地主机上运行测试或开发时,如何使用 tomcat7-maven-plugin 目标(例如 run)来模拟它?

如果不手动复制罐子,我看不到任何方法。我可以看到如何使用 test 类路径 - 我正在尝试做的事情有什么问题吗?

【问题讨论】:

    标签: maven tomcat dependencies classpath tomcat7


    【解决方案1】:

    好的,我已经找到了一种让它工作的方法——它是合理的,但是存在重复的依赖信息和一个神奇的配置文件......我觉得 tomcat7-maven-plugin 应该提供一种方法来制作提供的依赖项运行时在容器中可用。

    添加一个在tomcat插件运行时激活的配置文件,并将具有provided范围和compile范围的依赖项添加到该配置文件,例如。

    ... in project pom ...
    <dependencies>
      <dependency>
        <groupId>com.mycompany</groupId>
        <artifactId>my-provided-artifact</artifactId>
        <version>1.2.3</version>
        <scope>provided</scope>
      </dependency>
    </dependencies>
    ...
    <profiles>
      <profile>
        <!-- profile activated as cli param when tomcat7 plugin runs -->
        <id>tomcat</id>
        <dependencies>
          <dependency>
            <groupId>com.mycompany</groupId>
            <artifactId>my-provided-artifact</artifactId>
            <version>1.2.3</version>
            <scope>compile</scope>
          </dependency>
        </dependencies>
      </profile>
    </profiles>
    

    【讨论】:

      【解决方案2】:

      例如,我使用这个:

      <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.0</version>
          <configuration>
              <path>/myApp</path>
          </configuration>
          <dependencies>
              <dependency>
                  <groupId>com.oracle</groupId>
                  <artifactId>ojdbc6</artifactId>
                  <version>11.2.0.3</version>                    
              </dependency>
          </dependencies>
      </plugin>
      

      然后在稍后再次包含依赖项。

      【讨论】:

        猜你喜欢
        • 2014-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-19
        • 2017-08-25
        • 1970-01-01
        相关资源
        最近更新 更多