我有一個架構,其中JAXB
每次都能夠完美地生成java類。我試圖讓hyperjaxb
處理相同的模式。爲此,我下載並解壓縮了hyperjaxb
maven項目from this link,然後使用cmd.exe
導航到根目錄,並通過運行mvn clean install
以確保它與示例模式一起使用示例數據對其進行測試。然後,我用JAXB
完美工作完整的shema替換了schema.xsd
,po.xml
和bindings.xjb
文件,其中包括一些導入的命名空間。然後我再次運行mvn clean install
。不過,我收到以下錯誤消息:不受支持的綁定名稱空間「」
[ERROR] Error while parsing schema(s).Location [ file:/C:/path/to/src/main/resources/schema.xsd{4,32}].
org.xml.sax.SAXParseException; systemId: file:/C:/path/to/src/main/resources/schema.xsd;
lineNumber: 4; columnNumber: 32; Unsupported binding namespace "".
Perhaps you meant "http://annox.dev.java.net"?
在示例中,在schema.xsd頂端的架構標籤:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0">
與此相反,我的自定義模式使用:
<xs:schema targetNamespace="urn:some-org:v3" xmlns:mif="urn:some-org:v3/mif" xmlns="urn:some-org:v3"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
xmlns:sdtc="urn:some-org:sdtc" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0">
請注意我的自定義架構中架構標記中的xmlns="urn:some-org:v3"
。它不包括像xmlns:somequalifier="urn:some-org:v3"
這樣的限定符。這是造成這個問題嗎?它在沒有限定符的JAXB中完美工作。遍歷整個名稱空間並在每種類型前添加一個限定符將是一個主要的痛苦。
或者,可能是在示例項目的pom.xml中定義的結構(在上面鏈接的zip文件中)導致了問題。它們與基本的JAXB工具不同。
我該如何避免這個問題?最好不添加每個類型的限定符。我的模式中有幾千行。
堆棧跟蹤的以下行可能揭示:
[ERROR] Error while parsing schema(s).Location [ file:/C:/path/to/src/main/resources/schema.xsd{4,32}].
org.xml.sax.SAXParseException; systemId: file:/C:/path/to/src/main/resources/schema.xsd; lineNumber: 4; columnNumber: 32; Unsupported binding namespace "". Perhaps you meant "http://annox.dev.java.net"?
at com.sun.tools.xjc.reader.AbstractExtensionBindingChecker.error(AbstractExtensionBindingChecker.java:213)
at com.sun.tools.xjc.reader.AbstractExtensionBindingChecker.checkAndEnable(AbstractExtensionBindingChecker.java:115)
at com.sun.tools.xjc.reader.ExtensionBindingChecker.startElement(ExtensionBindingChecker.java:133)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker.startElement(IncorrectNamespaceURIChecker.java:128)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.startElement(CustomizationContextChecker.java:193)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner$LocationResolver.startElement(DOMForestScanner.java:147)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:244)
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:127)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:92)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:100)
at com.sun.tools.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:104)
at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:269)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:347)
at com.sun.xml.xsom.impl.parser.ParserContext.parse(ParserContext.java:128)
at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:168)
at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:157)
at com.sun.tools.xjc.ModelLoader.createXSOM(ModelLoader.java:534)
at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:378)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:174)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:119)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.loadModel(XJC22Mojo.java:50)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:40)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:28)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:318)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:161)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
您可以添加所有涉及的xsd嗎?抱歉,這個問題對我來說不是很清楚。 – Xstian 2014-10-16 21:13:17
@Xstian我把整個'resources'目錄,包括所有'xsd',上傳到一個zip文件。我懷疑'codehaus。mojo'插件是問題,但我不確定。這裏是鏈接:https://jumpshare.com/v/QsE0KEFiUV2CyMvneoJ9?b=7JBK9muM8YTIqVmwoItO – CodeMed 2014-10-16 21:17:15
@ Xstian你需要一個xml文件來匹配xsd嗎? – CodeMed 2014-10-16 21:37:08