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

查看:76
本文介绍了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.

我正在使用运行在 Sun Java 1.6.0-13 JDK之上的 JBoss 5.0.1.GA 应用程序服务器。对于生成的Web Service中的WAR文件,我使用 Axis2 1.4 WS引擎,其 Eclipse Galileo 将其JAR文件插入项目的 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时的类加载器(org / jboss / classloader / spi / base / BaseClassLoader的实例)引用类,javax / xml / xpath / XPathConstants,以及字段解析类型的类加载器(< bootloader>的实例),javax / xml / namespace / QName,具有该类型的不同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)&mdash ;但有时候我需要得到(例如)一个 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 /认可/ STAX-api.jar文件);和

    • Axis2部署的库( $ JBOSS_HOME / server / deploy / MyProject.ear / MyProject.war / WEB-INF / lib / axis2-saaj-api- 1.4.jar woden-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).

      提前感谢。

      推荐答案

      似乎通过删除 javax解决了这个问题。 xml.namespace。* 包和已部署的Axis2 JAR文件中的相应类。即,使用 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对项目非常挑剔组态。到目前为止,我发现使用版本 2.4 的动态Web模块创建了动态Web项目的Project Facet (而不是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天全站免登陆