SAXParseException; src-resolve: Cannot resolve the name '…' to a(n) 'type definition' component

本小妞迷上赌 提交于 2019-12-01 15:20:10

I've had this issue before. Everything validated in Eclipse, but broke when running. Do any of your schemas import more than one schema into the same namespace?

Something like this will not work, but will be validated by Eclipse:

<import namespace="http://www.whatever.gov" location="../wherever" />
<import namespace="http://www.whatever.gov" location="../folder/superawesomeschema.xsd" />

Lots of people have encountered this type of issue before. It comes up whenever your validator is, for whatever reason, not loading the schema documents you want it to load (and think it's loading).

To confirm the diagnosis: try introducing an error -- say, a well-formedness error -- into ObjectHistory_1_0.xsd, and see if the system complains.

Adrien Vercoutere

Using Xerces this can solved by setting the feature http://apache.org/xml/features/honour-all-schemaLocations to true.

The feature http://apache.org/xml/features/honour-all-schemaLocations is only available from Xerces 2.7.0. Current releases of Java 5.0 and 6.0 have a Xerces 2.6.2 built-in. Hence one has to use a newer Xerces library in order for this to work, ie. copying xml-apis.jar and xercesImpl.jar to <jdk-home>/jre/lib/endorsed and creating a jaxp.properties file in <jdk-home>/jre containing the line

javax.xml.validation.SchemaFactory\:http\://www.w3.org/2001/XMLSchema=org.apache.xerces.jaxp.validation.XMLSchemaFactory

I had the same problem when executing the maven plugin jaxb2-maven-plugin. After explicitly mentionning the xsd file to parse, it worked like a charm:

<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>jaxb2-maven-plugin</artifactId>
 <version>1.6</version>
    <executions>
     <execution>
      <id>xjc</id>
      <goals>
       <goal>xjc</goal>
      </goals>
     </execution>
    </executions>
    <configuration>
     <schemaFiles>MySchema.xsd</schemaFiles>
     <outputDirectory>src/main/java</outputDirectory>
    </configuration>
</plugin> 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!