Announcement Announcement Module
Collapse
No announcement yet.
Spring XML schema validation and Xerces Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring XML schema validation and Xerces

    All:

    I'm having an issue where a Spring application, when run from the command line, can not find an XML parser that supports XSD validation. This does not occur within Eclipse during development / unit testing. Eclipse and the command line are both referring to the same JDK (java-6-sun-1.6.0.13). I'm using Ivy with the Spring Enterprise Bundle Repository and pulling in cyberneko for HTML parsing[1]. One of Neko's dependencies is Xerces 2.8.1 which, while slightly older than the current 2.9.1, is still perfectly capable of XSD validation. It is this dependency that results in the exception below.

    If I add an exclusion to my Ivy file so Xerces is not included (banking on what's included with the JDK, itself), the code compiles, runs, and properly parses the Spring configs (with schema validation), but Neko fails due to org.apache.xerces.DOMParser not being found.

    Again, all of this works fine in Eclipse so clearly it's a classpath issue of some kind. I've tried doing things like logging the java.class.path property from the unit tests in Eclipse and running with things in that order, but that produces similar results.

    Note the specific line in the stack trace that shows that it's using Xerces' org.apache.xerces.jaxp.DocumentBuilderFactoryImpl class which should suffice.

    [1] http://www.springsource.com/reposito...version=1.9.11

    Code:
    [main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/spring/xxx.xml]
    [main] ERROR xxx.Application - Error running application. Exception follows.
    org.springframework.beans.factory.BeanDefinitionStoreException: Parser configuration exception parsing XML from class path resource [META-INF/spring/xxx.xml]; nested exception is javax.xml.parsers.ParserConfigurationException: Unable to validate using XSD: Your JAXP provider [org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@5f8172] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) forfull XSD support.
            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
            at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
            at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:80)
            at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
            at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
            at xxx.Application.run(Unknown Source)
            at xxx.Application.main(Unknown Source)
    Caused by: javax.xml.parsers.ParserConfigurationException: Unable to validate using XSD: Your JAXP provider [org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@5f8172] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.
            at org.springframework.beans.factory.xml.DefaultDocumentLoader.createDocumentBuilderFactory(DefaultDocumentLoader.java:102)
            at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:70)
            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
            ... 15 more
    Caused by: java.lang.IllegalArgumentException: Feature 'http://apache.org/xml/features/validation/schema' is not recognized.
            at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(Unknown Source)
            at org.springframework.beans.factory.xml.DefaultDocumentLoader.createDocumentBuilderFactory(DefaultDocumentLoader.java:99)
            ... 17 more
    Everything else I've found on the subject says to stick xerces in the JDK/JRE endorsed directory, but this seems hackish and not necessary. Am I missing something?

    Any help is greatly appreciated.

  • #2
    As a quick follow up, I did try adding xerces 2.9.1 to the JRE's lib/ext directory as recommended in other posts. No luck, though; same results.

    Comment


    • #3
      One of my coworkers found the answer to this particular issue. I thought I should post it.

      Turns out that ivy was downloading source jars as well as well as binary jars. Cyberneko's source jar (but not the binary) contains a META-INF/services/<evil xml properties here> file which was the source of all the trouble. Eclipse was "smart" enough to ignore source jars for anything other than source reference, hence why it worked there, where as ant happily included it. Of course, ant was just doing what I asked it to do, as was ivy, so...

      Anyway, just in case someone runs into this later.

      Comment


      • #4
        Thank you posting your problem and resolution. I to am using Spring 3, Xerces 2.11 and Neko and was having troubles from ant (command-line). I removed the Neko sources from my "lib" directory and wa-la! I spent way to much time trying to figure out what was happening, but thank you!

        Now I just need to update my ant build or ivy config to exclude the neko sources.

        Comment


        • #5
          Thank you esammer, you just saved my day.
          Eclipse and source bundles, my favorite subject...

          Comment

          Working...
          X