java.lang.LinkageError:加载程序约束违规:加载程序 [英] java.lang.LinkageError: loader constraint violation: loader

查看:696
本文介绍了java.lang.LinkageError:加载程序约束违规:加载程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用HttpPost进行连接时,我遇到以下错误

Here I am getting below error while connect using HttpPost,

Caused by: java.lang.LinkageError: loader constraint violation: loader
 (instance of org/jboss/osgi/framework/internal/HostBundleClassLoader) 
 previously initiated loading for a different type with name
 "org/apache/http/client/methods/HttpPost"

我正在使用OSGI捆绑软件,所以我添加了所有必需的从属文件.

And I am using OSGI bundle so I have added all required dependent files.

那么有人可以帮助我解决它吗?

So can anyone help me to resolve it?

推荐答案

Java 语言基于单个命名空间.也就是说,该语言是基于仅一次使用类名的概念而构建的.类加载器旨在通过Internet加载代码,但是偶然地允许2个类加载器使用相同的类名称.

The Java language is based on a single namespace. That is, the language is built around the concept that a class name is used only once. Classloaders were designed to load code over the internet but accidentally allowed the same class name to be used by 2 class loaders.

在OSGi中,每个捆绑软件都有一个类加载器,该类加载器直接从其 own 捆绑软件中加载类,但对所有导入的 other 捆绑软件使用类加载器类.

In OSGi, each bundle has a class loader that directly loads the classes from its own bundle but uses the class loader of other bundles for any imported classes.

在这样的类加载器的 mesh 中,您会遇到这样的情况:可以从Bundle加载类C,该Bundle引用从其他类加载器加载的类X和类Y.由于它们具有不同的名称,所以可以.但是,X可以引用Z类,Y可以引用Z,它们可以来自不同的装载机.因此,来自捆绑软件A的原始C类可以从两个不同的类加载器看到Z.这是一个链接错误.

In such a mesh of class loaders, you get the situation that you can load a class C from a Bundle that references a class X and a class Y loaded from other class loaders. Since they have different names that is ok. However, X could refer to class Z and Y could refer to Z, and they could come from different loaders. The original class C from Bundle A, therefore, can see Z from two different class loaders. And is a Linkage Error.

当所有捆绑包都正确时,这种 mesh 类加载器工作得很好,如果不 hack 捆绑包,则永远都不会出现这种错误.这些错误不可避免地是由复杂的设置引起的,这些设置不遵循OSGi规则,并且无法手动维护Bundle的清单.

This mesh of classloaders works very well when all bundles are correct, you should never get this kind of errors when you do not hack your bundles. These errors are inevitably caused by complex setups that do not follow the OSGi rules and maintain the Bundle's manifest by hand.

在这种情况下,可以多次看到的类名是org.apache.http.client.methods.HttpPost.因此,您有一个设置,其中有多个捆绑软件导出此类,这是第一个查找的地方.由于您可以启动捆绑软件,因此元数据是错误的. OSGi具有特殊的元数据,可以在启动捆绑包之前检测到此错误,即所谓的使用约束.

In this case, the class name that can be seen multiple times is org.apache.http.client.methods.HttpPost. So you have a setup where there are multiple bundles exporting this class, which is the first place to look. Since you could start the bundle, the metadata is wrong. OSGi has special metadata that makes this error detected before you start the bundle, the so-called uses constraints.

在Apache Felix上,您可以对问题进行广泛的分析.如果您可以在Apache Felix上运行代码,那将是最简单的方法.查看您的错误,您似乎正在JBoss上运行.他们总是对OSGi规则有些松懈,以使其更容易运行企业软件.很少提供OSGi元数据的软件,并且以其类加载器黑客程序而闻名. (很多人只是在Java模块系统才开始了解OSGi在做什么和需要什么之后.)

On Apache Felix, you get an extensive analysis of the problem. If you could run your code on Apache Felix, that would be the easiest route. Looking at your error, you seem to be running on JBoss. They always have played a bit loose with the OSGi rules to make it easier to run enterprise software. Software that rarely does the work to provide OSGi metadata and is well known for its class loader hacks. (A lot of people are only after the Java Module System starting to understand what OSGi was doing and needed.)

这篇关于java.lang.LinkageError:加载程序约束违规:加载程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆