Ibm mobilefirst IBM Liberty上MobileFirst适配器中的jax rs ClientBuilder

Ibm mobilefirst IBM Liberty上MobileFirst适配器中的jax rs ClientBuilder,ibm-mobilefirst,jax-rs,websphere-liberty,mobilefirst-adapters,Ibm Mobilefirst,Jax Rs,Websphere Liberty,Mobilefirst Adapters,我的目标是使用jax-rs客户端连接到MobileFirst Java适配器内的后端,但我真的被卡住了,需要帮助 引发异常的代码: javax.ws.rs.client.Client client = javax.ws.rs.client.ClientBuilder.newClient(); 引发的异常: java.lang.ClassNotFoundException:org.glassfish.jersey.client.JerseyClientBuilder` 代码位于IBM Liber

我的目标是使用jax-rs客户端连接到MobileFirst Java适配器内的后端,但我真的被卡住了,需要帮助

引发异常的代码:

javax.ws.rs.client.Client client = javax.ws.rs.client.ClientBuilder.newClient();
引发的异常:

java.lang.ClassNotFoundException:org.glassfish.jersey.client.JerseyClientBuilder`

代码位于IBM Liberty server上部署的MobileFirst server 8.0版上的Java适配器内

jaxrsClient-2.0和jaxrs-2.0功能在
server.xml
中的服务器功能管理器中启用

<feature>jaxrs-2.0</feature>
<feature>jaxrsClient-2.0</feature>

求求你,救命

我正在处理一个类似的需求,在解决异常之前,我尝试了许多组合。 我不知道liberty为什么不提供客户端实现类。。 您可以尝试通过maven pom.xml包含jersey客户端

<dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>2.23.1</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.moxy</artifactId>
            <version>2.6.1</version>
</dependency>

org.glassfish.jersey.core
泽西岛客户
2.23.1
org.eclipse.persistence
org.eclipse.persistence.moxy
2.6.1
在Server.xml中删除这些功能

<feature>jaxrs-2.0</feature>
<feature>jaxrsClient-2.0</feature>
jaxrs-2.0
jaxrsClient-2.0
只需添加以下功能

<feature>beanValidation-1.1</feature>
beanValidation-1.1
Liberty提供了一个客户端实现,但是parentLast类加载器委托阻止了它的使用


似乎MobileFirst正在打包Jersey,在这种情况下,应该禁用Liberty的JAX-RS功能,以便使用Jersey。这可能需要您更改在maven/gradle工件中声明依赖项的方式。

这看起来像是WebSphereLiberty中的一个bug,在16.0.0.4中修复。如果创建JAX-RS客户端新实例的类打包在OSGi包中(在OSGi应用程序中或作为Liberty功能的一部分),那么JAX-RS客户端运行时无法找到指定Liberty的JAX-RS客户端实现类(基于CXF)的META-INF/服务文件--因此JAX-RS运行时将退回到Jersey实现,除非您将其与应用程序打包,否则将找不到Jersey实现


描述了此问题的修复方法。基本上,Liberty使META-INF/services文件可供OSGi捆绑包使用。

Suresh的修复工作正常。不过,我只需要在pom.xml中添加更多依赖项。我想我不需要莫西在这里。。将进一步优化

<dependency>
    <groupId>org.glassfish.hk2</groupId>
    <artifactId>hk2-core</artifactId>
    <version>2.5.0-b61</version>
</dependency>
<dependency>
    <groupId>org.glassfish.hk2</groupId>
    <artifactId>hk2-api</artifactId>
    <version>2.5.0-b42</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-common</artifactId>
    <version>2.9.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.9.1</version>
</dependency>
<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.moxy</artifactId>
    <version>2.6.4</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.9.5</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.9.5</version>
</dependency>

org.glassfish.hk2
hk2核心
2.5.0-b61
org.glassfish.hk2
香港2号空气污染指数
2.5.0-b42
org.glassfish.jersey.core
泽西公地
2.9.1
org.glassfish.jersey.core
泽西岛客户
2.9.1
org.eclipse.persistence
org.eclipse.persistence.moxy
2.6.4
com.fasterxml.jackson.core
杰克逊核心
2.9.5
com.fasterxml.jackson.core
杰克逊数据绑定
2.9.5
<feature>beanValidation-1.1</feature>
<dependency>
    <groupId>org.glassfish.hk2</groupId>
    <artifactId>hk2-core</artifactId>
    <version>2.5.0-b61</version>
</dependency>
<dependency>
    <groupId>org.glassfish.hk2</groupId>
    <artifactId>hk2-api</artifactId>
    <version>2.5.0-b42</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-common</artifactId>
    <version>2.9.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.9.1</version>
</dependency>
<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.moxy</artifactId>
    <version>2.6.4</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.9.5</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.9.5</version>
</dependency>