[英]org.glassfish.jersey.internal.RuntimeDelegateImpl NOT FOUND
I am using jersey for my project and tring to parse a URI from a string.我在我的项目中使用 jersey 并尝试从字符串中解析 URI。
UriBuilder.fromUri("http://localhost:8000").build();
The code is simple, but I get a error below代码很简单,但下面出现错误
java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl
It seems the program can not find the delegate.程序似乎找不到委托。 I already imported
javax.ws.rs.core.UriBuilder
and have jersey-common 2.0
that should contain the delegate in my build path.我已经导入了
javax.ws.rs.core.UriBuilder
并拥有jersey-common 2.0
,它应该在我的构建路径中包含委托。 But I still get this error.但我仍然得到这个错误。
Does someone know how to fix it?有人知道如何解决吗? Thanks!
谢谢!
If you're using Maven, use the following dependency:如果您使用的是 Maven,请使用以下依赖项:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.22.2</version>
<scope>test</scope>
</dependency>
For Gradle, the following will work:对于 Gradle,以下内容将起作用:
testImplementation 'org.glassfish.jersey.core:jersey-common:2.22.2'
Developing against a Wildfly 10.1 runtime I didn't want to introduce Jersey into my builds.针对 Wildfly 10.1 运行时进行开发,我不想将 Jersey 引入我的构建中。 With Gradle I used
我用 Gradle
testRuntime "org.jboss.resteasy:resteasy-jaxrs:$versions.resteasy"
resteasy version is 3.0.19.Final. resteasy 版本是 3.0.19.Final。 This jar contains
这个罐子包含
META-INF/services/javax.ws.rs.ext.RuntimeDelegate
with an entry有一个条目
org.jboss.resteasy.spi.ResteasyProviderFactory
In my case the problem was for another Jar being used named: javax.ws.rs-api-2.0.jar在我的情况下,问题出在使用另一个名为: javax.ws.rs-api-2.0.jar 的Jar
Removing that jar solved my problem.删除那个罐子解决了我的问题。
The jar that I have used:我用过的罐子:
<include name="jersey-client-1.9.jar" />
<include name="jersey-core-1.9.jar" />
<include name="jersey-multipart-1.9.jar" />
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.26</version>
<scope>test</scope>
</dependency>
I ran into issues with Java 8 and jersey-common 2.22.2 but 2.26 worked.我遇到了 Java 8 和 jersey-common 2.22.2 的问题,但 2.26 有效。
tl;dr if you're using jersey-client 1.x within an app that has a "provider" class also present, and you have rs-api-2.1.jar there, you need to add jersey-server 1.x or remove rs-api-2.1 if you happen to also have jsr311-api-1.1.1 present. tl;博士如果您在一个应用程序中使用 jersey-client 1.x,并且该应用程序也存在“提供程序”类,并且您在那里有 rs-api-2.1.jar,则需要添加 jersey-server 1.x 或如果您碰巧也存在 jsr311-api-1.1.1,请删除 rs-api-2.1。
Appears this is what is happening:似乎这是正在发生的事情:
Apparently jersey-client, when it is first coming up, tries to create a "mime map" of different mime types.显然 jersey-client 刚出现时,会尝试创建不同 mime 类型的“mime map”。
jersey-core 1.x ContextResolverFactory: jersey-core 1.x ContextResolverFactory:
public void init(ProviderServices providersServices, InjectableProviderFactory ipf) {
Map<Type, Map<MediaType, List<ContextResolver>>> rs = new HashMap();
Set<ContextResolver> providers = providersServices.getProviders(ContextResolver.class);
Iterator i$ = providers.iterator();
while(i$.hasNext()) {
ContextResolver provider = (ContextResolver)i$.next();
List<MediaType> ms = MediaTypes.createMediaTypes((Produces)provider.getClass().getAnnotation(Produces.class));
...
So if there are any "providers" kicking around (ex: @Produces ({MediaType.WILDCARD})
), it tries to lookup their type and add it to the mime type lists.因此,如果有任何“提供者”出现(例如:
@Produces ({MediaType.WILDCARD})
),它会尝试查找他们的类型并将其添加到 mime 类型列表中。 However, it does it the following:但是,它执行以下操作:
if you have rs-api-2.1.jar:如果你有 rs-api-2.1.jar:
private static RuntimeDelegate findDelegate() {
try {
Object delegate = FactoryFinder.find("javax.ws.rs.ext.RuntimeDelegate", "org.glassfish.jersey.internal.RuntimeDelegateImpl", RuntimeDelegate.class);
If you have the following other dependency, it appears to implement it slightly differently:如果您有以下其他依赖项,它的实现方式似乎略有不同:
jsr311-api-1.1.1.jar: jsr311-api-1.1.1.jar:
private static RuntimeDelegate findDelegate() {
try {
Object delegate = FactoryFinder.find("javax.ws.rs.ext.RuntimeDelegate", "com.sun.ws.rs.ext.RuntimeDelegateImpl");
Jersey 1.x client happens to provide ./jersey-client-.19/com/sun/ws/rs/ext/RuntimeDelegateImpl.class
Jersey 1.x 客户端恰好提供
./jersey-client-.19/com/sun/ws/rs/ext/RuntimeDelegateImpl.class
Whereas Jersey 1.x server provides:而 Jersey 1.x 服务器提供:
./jersey-server-1.19/com/sun/jersey/server/impl/provider/RuntimeDelegateImpl.class
jersey 2.0 is "org.glassfish.jersey..." and provides "org.glassfish.jersey.internal.RuntimeDelegateImpl" (apparently sanely) jersey 2.0 是“org.glassfish.jersey ...”并提供“org.glassfish.jersey.internal.RuntimeDelegateImpl”(显然是理智的)
So it appears to me that rs-api-2.1
basically targets jersey 2.x by default.所以在我看来,
rs-api-2.1
默认基本上是针对 jersey 2.x 的。 But happens to work with jersey-client 1.x if you also include jersey-server.但是如果您还包含 jersey-server,则恰好可以与 jersey-client 1.x 一起使用。
With jersey 2.x you don't need to include the "server to use the client" in such a weird way, seems to just work.使用 jersey 2.x,您不需要以这种奇怪的方式包含“使用客户端的服务器”,似乎可以正常工作。
My hunch is either the API changed (you're not supposed to combine jersey 1.x with jsr-2? huh?), or maybe accidental flub, or bug, or poor design of jersey-client 1.x, who knows.我的预感要么是 API 改变了(你不应该将 jersey 1.x 与 jsr-2 结合起来吗?嗯?),或者可能是意外的失误、错误或 jersey-client 1.x 的糟糕设计,谁知道呢。
Adding things that happen to add "jersey 2.x" or "jersey-server 1.x" transitively also works.添加碰巧添加“jersey 2.x”或“jersey-server 1.x”的东西也可以传递。
These worked around the following runtime failure:这些解决了以下运行时故障:
Caused by: java.lang.ExceptionInInitializerError: null
at com.sun.jersey.core.spi.factory.ContextResolverFactory.init(ContextResolverFactory.java:86)
at com.sun.jersey.api.client.Client.init(Client.java:340)
at com.sun.jersey.api.client.Client.access$000(Client.java:119)
at com.sun.jersey.api.client.Client$1.f(Client.java:192)
at com.sun.jersey.api.client.Client$1.f(Client.java:188)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.api.client.Client.<init>(Client.java:188)
at com.sun.jersey.api.client.Client.<init>(Client.java:171)
at redacted
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at org.familysearch.digitalarchive.aggregator.integration.ServiceAccountConfig$$EnhancerBySpringCGLIB$$a3409578.identityService(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 29 common frames omitted
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:154)
at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:121)
at javax.ws.rs.core.MediaType.valueOf(MediaType.java:196)
at com.sun.jersey.core.header.MediaTypes.<clinit>(MediaTypes.java:65)
... 48 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:111)
at javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:209)
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:136)
... 51 common frames omitted
Please use UriComponents instead URI请使用 UriComponents 代替 URI
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://localhost:8000").build();
Then you can get URI object like然后你可以得到URI对象
uriComponents.toUri()
compile 'org.springframework.boot:spring-boot-starter-jersey:1.2.0.RELEASE'
这对我有用!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.