【问题标题】:Adding a jar to jetty plugin for maven为maven添加一个jar到码头插件
【发布时间】:2012-10-11 18:21:22
【问题描述】:

我曾经在本地 tomcat 服务器上部署我的 WAR,并且在 tomcat 的lib 文件夹中有一个 jackson-core.jar。现在,我已经切换到 maven 并且正在使用 jetty 插件。

除了我收到406 error - The server responded with 406 error (Not acceptable) 之外,一切正常。我知道错误即将到来,因为应用服务器(码头)中没有 jackson-core.jar。

问题:

我怎样才能像在独立的 tomcat 服务器上那样在嵌入式码头的 lib 文件夹中放置一个 jar。这可能吗?

我尝试了以下方法:

<configuration>
  <scanIntervalSeconds>5</scanIntervalSeconds>
  <webAppConfig>
  <contextPath>/myapp</contextPath>
  <extraClasspath>/Users/myuser/Downloads/jackson-core-2.1.0.jar</extraClasspath>
  </webAppConfig> 
</configuration>

【问题讨论】:

    标签: tomcat maven embedded-jetty maven-jetty-plugin


    【解决方案1】:

    您可以通过在插件定义中添加&lt;dependencies&gt; 部分来修改插件的类路径(而不是项目的类路径)。例如

    <project>
      ...
      <build>
        ...
        <plugins>
          ...
          <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.0.4.v20111024</version><!-- or whatever version you specified -->
            <configuration>
              ...
            </configuration>
            ...
            <dependencies>
              <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>2.1.0</version>
              </dependency>
            </dependencies>
            ...
          </plugin>
          ...
        </plugins>
        ...
      </build>
      ...
    </project>
    

    现在您可能使用的是较旧版本的 Jackson,甚至是较旧的 API(它存在于不同的 GroupId:ArtifactId,因为它破坏了向后兼容性),因此您需要进行自己的研究以确保您选择了正确的一个。

    大多数更高级的插件都使用添加&lt;plugin&gt; 范围依赖项的一般原则。有一个或两个小问题,即您要覆盖插件本身的依赖项,即您添加的依赖项的 groupId:artifactId 与插件 pom 中声明的依赖项的 groupId:artifactId 匹配,您的条目将采用谨慎,如果您将版本拉低,您可能会破坏插件......但码头和杰克逊不会出现这种情况。

    jetty 的另一个特殊问题是,当您引入 slf4j-api 依赖项时,jetty 将尝试使用它进行日志记录,并且考虑到 slf4j API 的一小块区域中的一些破坏性 API 更改(特别是与编写日志适配器 - 哪个码头做)如果你不使用属于你正在使用的码头版本的 slf4j 版本的 slf4j-_ jar 套件,你可能会遇到问题。 .

    【讨论】:

      【解决方案2】:

      只需将依赖项添加到插件的&lt;dependencies/&gt; 部分即可。应该这样做。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-02
        • 1970-01-01
        • 2016-05-14
        • 2023-04-02
        相关资源
        最近更新 更多