java JBoss5 中的 XPath 类解析

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3247662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 00:59:21  来源:igfitidea点击:

XPath class resolution in JBoss5

javaxpathjbossclassloader

提问by jbatista

I'm having a hard time figuring out where the problem is coming from, so I'm posting this in the hopes that others might have found something similar to this elsewhere and are kind enough to share their insight.

我很难弄清楚问题是从哪里来的,所以我发布这个是希望其他人可能会在其他地方找到类似的东西,并愿意分享他们的见解。

I'm using a JBoss 5.0.1.GAapplication server running on top of a Sun Java 1.6.0-13 JDK. For the WAR file in the generated Web Service, I use a Axis2 1.4WS engine whose JAR files are inserted by Eclipse Galileointo the project's WEB-INF/libdirectory when creating the Webservice from the given "worker" class in the Dynamic Web Project. The relevant code snippet follows:

我正在使用运行在Sun Java 1.6.0-13 JDK之上的JBoss 5.0.1.GA应用服务器。对于生成的 Web 服务中的 WAR 文件,我使用Axis2 1.4WS 引擎,当从动态 Web 项目中给定的“worker”类创建Web 服务时,Eclipse Galileo将其 JAR 文件插入到项目目录中。相关代码片段如下:WEB-INF/lib

String sUrl = "http://example.com/datafile.xml";
String sPath = "/some/xpath/string";
InputStream input = new URL(sUrl).openStream();
InputSource source = new InputSource(input);
DocumentBuilderFactory docFact = DocumentBuilderFactory.newInstance();
docFact.setNamespaceAware(false);
DocumentBuilder parser = docFact.newDocumentBuilder();
Document doc = parser.parse(source);
XPath xpath = XPathFactory.newInstance().newXPath();
// error occurs here:
String result = (String) xpath.evaluate(path,doc,XPathConstants.STRING);
input.close();

This is the error I'm getting from the JBoss log:

这是我从 JBoss 日志中得到的错误:

java.lang.LinkageError: loader constraint violation: when resolving field "STRING" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the referring class, javax/xml/xpath/XPathConstants, and the class loader (instance of <bootloader>) for the field's resolved type, javax/xml/namespace/QName, have different Class objects for that type

java.lang.LinkageError:加载器约束冲突:解析字段“STRING”时引用类的类加载器(org/jboss/classloader/spi/base/BaseClassLoader的实例),javax/xml/xpath/XPathConstants,以及类loader(<bootloader> 的实例)对于字段的解析类型 javax/xml/namespace/QName,对于该类型具有不同的 Class 对象

I coulduse the XPath.evaluate(String,Document)— however there are occasions where I need to get (for example) a XPathConstants.NODESETinstead, so it's a no-go. I have also tried to fumble a little by littering some jboss-web.xmlfiles here and there in the WAR file, but with no effect.

可以使用XPath.evaluate(String,Document)- 但是在某些情况下我需要得到(例如)aXPathConstants.NODESET代替,所以这是不行的。我还试图通过jboss-web.xml在 WAR 文件中到处乱扔一些文件来摸索,但没有任何效果。

What I'm trying to understand is:

我想了解的是:

  • Where could the error be coming from? The JBoss class loader? Some weird interaction between JBoss and the Sun JDK? Some weirdness introduced by Eclipse when creating the Web Service? Maybe some confusion introduced by the Axis2 libraries deployed within the WAR?
  • I've found instances of compiled class files in what looks like a triple-whammie:
    • Sun JDK (file rt.jar);
    • JBoss libraries ($JBOSS_HOME/lib/endorsed/stax-api.jar); and
    • Axis2-deployed libraries ($JBOSS_HOME/server/deploy/MyProject.ear/MyProject.war/WEB-INF/lib/axis2-saaj-api-1.4.jarand woden-impl-dom-1.0M8.jar).
  • How exactly am I supposed to configure JBoss to tell it which classes it's OK to load from "other" libraries from? Specifically, the jaxax.xml.namespace.QNameis is causing the grief.
  • 错误可能来自哪里?JBoss 类加载器?JBoss 和 Sun JDK 之间的一些奇怪的交互?Eclipse 在创建 Web 服务时引入了一些奇怪的东西?也许部署在 WAR 中的 Axis2 库引入了一些混乱?
  • 我发现编译类文件的实例看起来像三重打击:
    • Sun JDK(文件rt.jar);
    • JBoss 库 ( $JBOSS_HOME/lib/endorsed/stax-api.jar); 和
    • Axis2 部署的库($JBOSS_HOME/server/deploy/MyProject.ear/MyProject.war/WEB-INF/lib/axis2-saaj-api-1.4.jarwoden-impl-dom-1.0M8.jar)。
  • 我到底应该如何配置 JBoss 以告诉它可以从“其他”库加载哪些类?具体来说,jaxax.xml.namespace.QName是造成了悲伤。

Thank you in advance.

先感谢您。

采纳答案by jbatista

It seems that the problem was solved by removing the javax.xml.namespace.*package and respective classes from the deployed Axis2 JAR files. Namely, using Axis2 1.4.1(instead of 1.4), I repackaged these JAR files:

似乎通过javax.xml.namespace.*从部署的 Axis2 JAR 文件中删除包和相应的类来解决问题。即,使用Axis2 1.4.1(而不是 1.4),我重新打包了这些 JAR 文件:

  • axis2-saaj-api-1.4.1.jar, by removing javax.xml.namespace
  • woden-impl-dom-1.0M8.jar, by removing javax
  • axis2-saaj-api-1.4.1.jar, 通过删除 javax.xml.namespace
  • woden-impl-dom-1.0M8.jar, 通过删除 javax

Also, Eclipse is extremely picky at the project configuration. So far, I've found that the Project Facet for the Dynamic Web Project hasto be created with a Dynamic Web Module of version 2.4(and not 2.5 as it suggests by default), but with a Java version 6(same as the branch of the used JDK). I don't know why this happens, I suppose the Dynamic Web Module version 2.4 tying up by default with Java 1.4 in Eclipse is where all the confusion comes from. Some googling led me to believe that package javax.xml didn't become incorporated into the JDK until Java 5 or Java 6 -- hence the possible mixup! However, I'm not knowledgeable enough to investigate if the problem comes from how Eclipse packages the archive files for deployment so this is just a suspicion I have so far.

此外,Eclipse 对项目配置非常挑剔。到目前为止,我已经发现,该项目小面对动态Web项目具有与版本的动态Web模块创建2.4(和它表明在默认情况下没有2.5),但与Java版本6(与使用的JDK的分支相同)。我不知道为什么会发生这种情况,我想动态 Web 模块 2.4 版默认与 Eclipse 中的 Java 1.4 绑定是所有混淆的来源。一些谷歌搜索让我相信包 javax.xml 直到 Java 5 或 Java 6 才被合并到 JDK 中——因此可能会混淆!但是,我没有足够的知识来调查问题是否来自 Eclipse 如何打包存档文件以进行部署,所以这只是我迄今为止的一个怀疑。

回答by skaffman

JBoss will throw a LinkageErrorwhen the application's classpath contains classes which JBoss considers "protected", i.e. it does not permit the application to contain its own copies of certain key APIs.

LinkageError当应用程序的类路径包含 JBoss 认为“受保护”的类时,JBoss 将抛出,即它不允许应用程序包含它自己的某些关键 API 的副本。

In this case, it looks like your appcontains its own copies of the javax.xml.xpathAPI, and possibly some others as well, as you mentioned.

在这种情况下,您的应用程序似乎包含自己的javax.xml.xpathAPI副本,可能还有其他一些副本,正如您所提到的。

You need to remove anything from your EAR/WAR's lib directories that clashes with JBoss's own libraries (e.g. axis2-saaj-api-1.4.jar).

您需要从 EAR/WAR 的 lib 目录中删除与 JBoss 自己的库(例如axis2-saaj-api-1.4.jar)冲突的任何内容。