简体   繁体   中英

How can I force a JBoss deployment to use a specific version of a dependency instead of installed modules?

When deploying an *.ear to JBoss, it always uses the wrong version of com.fasterxml.jackson.core .

My code is using featuers of com.fasterxml.jackson.core version 2.9.0 and compiles fine, but when calling the code in JBoss, I got java.lang.NoSuchFieldError .

To me it seems, that JBoss classloader uses the already installed jackson module version 2.5.0.

How can I have JBoss classloader to use version 2.9.0 for my deployment?

Situation

I am developing a plugin for Keycloak , which I test locally by deploying it via the Keycloak Docker Image Version 3.2.1.

The ear is deployed by copying it to $JBOSS_HOME/standalone/deployments before launching the image, and the plugin works fine until I use functions from jackson 2.9.

What I have tried so far:

I pinned the version via 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>

I excluded the jackson-modules in my jboss-deployment-structure.xml:

<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>

I checked the dependencies tree:

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

The jackson 2.5 library is pre-installed since Keycloak depends on it:

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

When I unzip my *.ear package, I find the jackson-jars with correct version in libs/ ( META-INF/MANIFEST.MF says Bundle-Version: 2.9.0 :

ls  lib  | grep jackson
jackson-annotations.jar
jackson-core.jar
jackson-databind.jar

Can anyone explain to me, if and how I can make JBoss use the correct version of jackson?

Thank you!

Try adding the following modules to <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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM