我曾经在本地 tomcat 服务器上部署我的 WAR,并且在 tomcat 的 lib
文件夹中有一个 jackson-core.jar。现在,我已经切换到 Maven 并正在使用 jetty 插件。
一切正常,除了我收到 406 错误 - 服务器响应 406 错误( Not Acceptable )
我知道错误即将到来,因为应用程序服务器( jetty )没有 jackson - core.jar 在里面。
问题:
如何将 jar 放入嵌入式 jetty 的 lib 文件夹中,就像我为独立的 tomcat 服务器所做的那样。这可能吗?
我试过以下方法:
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
<webAppConfig>
<contextPath>/myapp</contextPath>
<extraClasspath>/Users/myuser/Downloads/jackson-core-2.1.0.jar</extraClasspath>
</webAppConfig>
</configuration>
最佳答案
您可以通过添加 <dependencies>
来修改插件的类路径(相对于项目的类路径)部分到插件定义。例如
<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 中,因为它破坏了向后兼容性)因此您需要进行自己的研究以确保您选择了正确的一个。
添加<plugin>
的一般原则大多数更高级的插件都使用作用域依赖项。有一个或两个小问题,即您要覆盖插件本身的依赖项,即您要添加的依赖项的 groupId:artifactId 与插件 pom 中声明的依赖项的 groupId:artifactId 相匹配,您的条目将采用precidence,如果你将版本拉低,你可能会破坏插件......但对于 jetty 和 jackson 来说情况并非如此。
jetty 的另一个具体问题是,当您引入 slf4j-api 依赖项时,jetty 将尝试使用它来进行日志记录,并在 slf4j API 的一小部分中给出一些破坏性的 API 更改(特别是与编写日志记录适配器 - jetty 做的)如果你不使用属于 slf4j 版本的 slf4j-_ jar 套件,你可能会遇到问题,你正在使用的 jetty 版本设计用于.
关于tomcat - 添加一个 jar 到 maven 的 jetty 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13002995/