JBoss5 中的 XPath 类解析 [英] XPath class resolution in JBoss5

查看:15
本文介绍了JBoss5 中的 XPath 类解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难弄清楚问题出在哪里,所以我发布了这篇文章,希望其他人可能在其他地方发现了类似的东西,并愿意分享他们的见解.

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.

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

I'm using a JBoss 5.0.1.GA application 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.4 WS engine whose JAR files are inserted by Eclipse Galileo into the project's WEB-INF/lib directory when creating the Webservice from the given "worker" class in the Dynamic Web Project. The relevant code snippet follows:

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();

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

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

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

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

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

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

我想了解的是:

  • 错误可能来自哪里?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).
    • 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.jar and woden-impl-dom-1.0M8.jar).

      提前致谢.

      推荐答案

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

      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:

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

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

      Also, Eclipse is extremely picky at the project configuration. So far, I've found that the Project Facet for the Dynamic Web Project has to 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.

      这篇关于JBoss5 中的 XPath 类解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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