我正在使用为keycloak创建插件(提供者)。我已经造了几个。现在,我需要添加客户端库来查询graphql服务器。但是,当我部署插件时,在类路径中找不到库。
问题
背景信息
我成功地为它创建了一个类和集成测试。但是,当我将插件部署到keycloak时,会出现以下错误:
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.jarBellow是JBos-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>我使用的是Keycloak11.0.2 (WildFly Core 12.0.3)。
发布于 2020-12-24 11:01:13
我不确定是否正确地理解了将库静态添加到jboss中的部分。我会从我理解你的问题来回答。您的问题有多种解决方案。
Jboss依赖关系
首先,您应该了解JBoss如何解决它的类和依赖关系。我会非常简单地解释。JBoss分为模块和部署。
模块被放置在JBoss的主文件夹中。模块是您在运行时不会更改的库。每个模块都有名为module.xml的描述符文件,您可以在其中定义构件、依赖项和模块名称。在模块世界中,文件module.xml基本上类似于jboss-deployment-structure.xml。
部署放在部署文件夹中,可以在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 (假设您的库是一个部署)
因此,例如,如果您希望在keycloak模块路径中依赖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中。您可以在keycloak层后面写逗号,如下所示:
layers=keycloak,[your layer]创建之后,您可以将插件添加到您的层中,例如:modules/system/layers/[name of your layer]/org/my/plugins/main
文件夹的内部将是:
jar
然后,您要做的唯一一件事就是将此模块作为依赖项包含在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
如果你不喜欢手动创建这个东西,你可以创建,比如这个。它将使用maven创建模块xml:
https://github.com/marcel-ouska/jboss-modules-builder
解决方案2- Fat JAR/WAR
基本上,如果您想要一个简单的解决方案,可以直接使用maven/Gradle插件将库添加到JAR/WAR中。
http://tutorials.jenkov.com/maven/maven-build-fat-jar.html
我不建议使用Fat JAR/WAR解决方案,因为通过添加更多的插件,您可能会迷失在依赖项和错误中,例如重复依赖类的情况。
发布于 2022-12-01 09:27:32
您必须在src/main/resources/META-INF目录中添加jboss-deployment-structure.xml文件。
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.microsoft" />
</dependencies>
</deployment>
</jboss-deployment-structure>

它必须在keycloak服务器modules目录中调用一个真正的模块。

https://stackoverflow.com/questions/65411688
复制相似问题