在wildflyjar中包含第三方库(keydrope-spi)

zbwhf8kr  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(346)

我正在使用服务提供者接口为keydove创建插件(提供者)。我已经建立了一个夫妇。现在我需要添加smallrye graphql客户机库来查询graphql服务器。但是,在部署插件时,在类路径中找不到库。

问题

仍然可以创建一个包含依赖库的jar吗?
如果1是不可能的,可以用战争来实现吗?
如何将库添加到类路径。最好是将它们与插件一起添加,而不是静态地添加到wildfly中。我在用gradle。更多细节如下。

背景信息

我成功地为它创建了一个类和集成测试。但是,当我将插件部署到key斗篷时,出现以下错误:

16:38:38,127 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-1) 
             Uncaught server error: java.util.ServiceConfigurationError: no 
             io.smallrye.graphql.client.typesafe.api.GraphQlClientBuilder in classpath

我已经将gradle配置为包含导致问题的依赖项,并将其添加到类路径中。我怀疑我应该在jboss-deployment-structure.xml中添加一个条目,但是我不知道应该在那里写什么。
梯度配置

plugins {
    id 'war'
    id 'java-library'
    id 'maven-publish'
}
repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
}
configurations {
    dependenciesToInclude
}
dependencies {
    dependenciesToInclude "io.smallrye:smallrye-graphql-client:1.0.20"

    providedCompile group: 'javax.enterprise', name: 'cdi-api', version: '2.0'
    providedCompile "org.keycloak:keycloak-server-spi:${keycloakVersion}"
    providedCompile "org.keycloak:keycloak-server-spi-private:${keycloakVersion}"
    providedCompile("org.keycloak:keycloak-services:${keycloakVersion}") {
        exclude group: 'org.slf4j', module: 'slf4j-api'
        exclude group: 'org.slf4j', module: 'slf4j-log4j12'
    }
    providedCompile group: 'org.keycloak', name: 'keycloak-model-api', version: '1.8.1.Final'
    providedCompile "org.jboss.resteasy:resteasy-jaxrs"

    providedCompile group: 'org.eclipse.microprofile.graphql', name: 'microprofile-graphql-api', version: '1.0.3'
    compile group: 'org.apache.geronimo.config', name: 'geronimo-config-impl', version: '1.2.2'
    configurations.compile.extendsFrom(configurations.dependenciesToInclude)
}

jar {
    manifest {
        attributes(
                "Class-Path": configurations.dependenciesToInclude.collect { it.getName() }.join(' '))
    }
    from {
        configurations.dependenciesToInclude.collect { it.isDirectory() ? it : zipTree(it) }
    }
}
❯ cat META-INF/MANIFEST.MF                                                                                                                                                                                                     ─╯
Manifest-Version: 1.0
Class-Path: smallrye-graphql-client-1.0.20.jar geronimo-config-impl-1.2.
 2.jar smallrye-graphql-client-api-1.0.20.jar microprofile-graphql-api-1
 .0.3.jar microprofile-config-api-1.3.jar org.osgi.annotation.versioning
 -1.0.0.jar

下面是jboss-deployment-structure.xml。在这里您可以看到我试图包含graphql库(注解掉)

<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="org.keycloak.keycloak-services"/>
            <module name="org.keycloak.keycloak-saml-core-public"/>
            <module name="org.apache.commons.codec"/>
            <module name="org.apache.commons.lang"/>
            <module name="org.jboss.logging"/>
            <!--            <module name="io.smallrye.smallrye-graphql-client"/>-->
        </dependencies>
    </deployment>
</jboss-deployment-structure>

我正在使用keydepe11.0.2(wildfly core12.0.3.final)

nle07wnf

nle07wnf1#

我不确定我是否正确理解了将库静态添加到jboss的过程。我将根据我所了解的情况回答你的问题。您的问题有多种解决方案。

jboss依赖项

您应该首先了解jboss如何解析其类和依赖项。我将非常简单地解释。jboss分为模块和部署。
模块放在jboss的主文件夹中。模块是在运行时不会更改的库。每个模块都有一个名为module.xml的描述符文件,您可以在其中定义工件、依赖项和模块的名称。文件module.xml基本上类似于模块世界中的jboss-deployment-structure.xml。
部署放在deployments文件夹中,可以在jboss服务器运行时重新部署。如果一个部署需要依赖于另一个模块/部署,那么它需要包含在给定部署的jboss部署结构中。 Note that modules cannot be dependent on deployments but it works the other way around 你可以在网上找到更多的信息,但这是你可以使用的基本信息。

解决方案1-jboss模块

如果您想获得对jboss中某个模块的依赖关系,则需要在module.xml中找到该模块的名称,并将其写入jboss-deployment-structure.xml(假设您的库是部署库)
因此,例如,如果您希望依赖于keydove modules路径中的jackson-dataformat-cbor-2.10.5.jar:

modules/system/layers/keycloak/com/fasterxml/jackson/dataformat/jackson-dataformat-cbor/main/jackson-dataformat-cbor-2.10.5.jar

同一文件夹中有一个module.xml,其内容为:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2019 Red Hat, Inc. and/or its affiliates
  ~ and other contributors as indicated by the @author tags.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<module name="com.fasterxml.jackson.dataformat.jackson-dataformat-cbor" xmlns="urn:jboss:module:1.3">
    <resources>
        <resource-root path="jackson-dataformat-cbor-2.10.5.jar"/>
    </resources>

    <dependencies>
        <module name="com.fasterxml.jackson.core.jackson-core"/>
        <module name="com.fasterxml.jackson.core.jackson-databind"/>
        <module name="com.fasterxml.jackson.core.jackson-annotations"/>
    </dependencies>
</module>

这意味着你的模块名是 com.fasterxml.jackson.dataformat.jackson-dataformat-cbor 这就是作为依赖关系放入jboss-deployment-structure.xml的内容。

你的案子

在你的情况下,你需要依赖 smallrye-graphql-client jboss模块中不包括的。也就是说你得把它加进去。通过在层中创建文件夹来创建jboss层: modules/system/layers/[name of your layer] 在这样做之后,你还应该包括你的层中 modules/layers.conf . 您可以在key斗篷层后面写逗号来包含它,如下所示:

layers=keycloak,[your layer]

创建之后,您可以向层中添加插件,例如: modules/system/layers/[name of your layer]/org/my/plugins/main 文件夹的内部将是:
你的jar
module.xml(根据其他模块创建)
那么您要做的唯一一件事就是将这个模块作为依赖项包含在jboss-deployment-structure.xml中(始终包括模块的名称) Note that you might have to add more libraries as dependencies to your modules. You can include all of it in the modules 万一你不知道´如果不想手动创建这些东西,您可以创建jboss模块生成器,比如这个。它将使用maven创建您的xml模块:
https://github.com/marcel-ouska/jboss-modules-builder

解决方案2-脂肪罐/战争

基本上,如果您想要一个简单的解决方案,您可以直接使用maven/gradle插件将库添加到jar/war中。
脂肪罐-http://tutorials.jenkov.com/maven/maven-build-fat-jar.html
战争-你的依赖自动打包
我不建议使用fatjar/war解决方案,因为添加更多插件时,您可能会在依赖项中迷失方向,并出现错误,例如重复依赖类的情况。

相关问题