在向JBoss部署* .ear时,它总是使用错误版本的com.fasterxml.jackson.core
。
我的代码正在使用com.fasterxml.jackson.core版本2.9.0的特性并编译得很好,但是当我在JBoss中调用代码时,我得到了java.lang.NoSuchFieldError
。
对我来说,似乎JBoss类加载器使用已安装的jackson模块版本2.5.0。
如何让JBoss类加载器使用版本2.9.0进行部署?
场合
我正在为Keycloak开发一个插件,我通过Keycloak Docker Image版本3.2.1部署它来进行本地测试。
在启动图像之前,通过将其复制到$ JBOSS_HOME / standalone / deployments来部署耳朵,插件工作正常,直到我使用jackson 2.9中的函数。
到目前为止我尝试了什么:
我通过pom.xml固定版本:
<dependencyManagement>
<dependencies>
<dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
我在jboss-deployment-structure.xml中排除了jackson-modules:
<deployment>
<dependencies>
<module name="org.keycloak.keycloak-core" export="true" />
<module name="org.keycloak.keycloak-server-spi" export="true" />
<module name="org.keycloak.keycloak-server-spi-private" export="true" />
<module name="org.keycloak.keycloak-services" export="true" />
<module name="org.bouncycastle" export="true" />
<module name="com.google.guava" export="true" />
<module name="org.jboss.logging" export="true" />
</dependencies>
<exclusions>
<module name="com.fasterxml.jackson.core.jackson-core" />
<module name="com.fasterxml.jackson.core.jackson-databind" />
<module name="com.fasterxml.jackson.core.jackson-annotations" />
</exclusions>
</deployment>
我检查了依赖树:
mvn dependency:tree | grep jackson
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.9.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-databind:jar:2.9.0:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] \- com.github.kittinunf.fuel:fuel-jackson:jar:1.12.0:runtime
[INFO] +- com.fasterxml.jackson.module:jackson-module-kotlin:jar:2.9.0:runtime
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.9.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-databind:jar:2.9.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] \- com.github.kittinunf.fuel:fuel-jackson:jar:1.12.0:runtime
[INFO] +- com.fasterxml.jackson.module:jackson-module-kotlin:jar:2.9.0:runtime
杰克逊2.5库已预先安装,因为Keycloak依赖它:
find ${JBOSS_HOME}/modules | grep jackson-core
/opt/jboss/keycloak/modules/system/layers/base/com/fasterxml/jackson/core/jackson-core
/opt/jboss/keycloak/modules/system/layers/base/com/fasterxml/jackson/core/jackson-core/main
/opt/jboss/keycloak/modules/system/layers/base/com/fasterxml/jackson/core/jackson-core/main/module.xml
/opt/jboss/keycloak/modules/system/layers/base/com/fasterxml/jackson/core/jackson-core/main/jackson-core-2.5.4.jar
当我解压缩我的* .ear包时,我在libs/
META-INF/MANIFEST.MF
说Bundle-Version: 2.9.0
{/ 1}}找到了正确版本的jackson-jars:
ls lib | grep jackson
jackson-annotations.jar
jackson-core.jar
jackson-databind.jar
任何人都可以向我解释,我是否以及如何让JBoss使用正确版本的jackson?
谢谢!
答案 0 :(得分:0)
尝试将以下模块添加到<exclusions>
。
<module name="org.jboss.resteasy.resteasy-jackson2-provider" />
<module name="com.fasterxml.jackson.module.jackson-module-jaxb-annotations" />
<module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" />
<module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-base" />