在从XSD架构生成源代码期间,我得到一个SAXParseException(见下文)。模式“gws-ctsa-myapp.xsd”正在导入两个基本组件“gws-services-types.xsd”和“gws-ctsa.xsd”。最后一个导入同样的基本组件“gws-services-types.xsd”,并且在类路径目录解析器上找到这两个基本组件。
我希望基本组件“gws-ctsa.xsd”中的导入对于模式“gws-ctsa-myapp.xsd”不可见,但遗憾的是并非如此。
当我在项目“project_root / myapp / myapp-jaxb”上运行“mvn compile”时,它运行正常。当我在项目根“project_root /”上运行它时,它不起作用。项目目录如下所示:
...
project_root/
project_root/common/
project_root/common/common-jaxb
...
project_root/myapp/
project_root/myapp/myapp-jaxb
...
这是异常堆栈跟踪:
[INFO] Started execution.
[INFO] JAXB API is loaded from the [jar:file:/C:/Program%20Files/Java/jdk1.6.0_22/jre/lib/rt.jar!].
[INFO] Detected JAXB API version [2.1].
[INFO] pluginArtifacts:[org.jvnet.jaxb2.maven2:maven-jaxb2-plugin-raw:jar:0.7.3:runtime, org.codehaus.plexus:plexus-utils:jar:1.1:runtime, ...
[INFO] schemaLanguage:null
[INFO] schemaDirectory:D:\eclipse\pbona\workspace\tobias-ROOT\myapp\myapp-jaxb\src\main\resources
[INFO] schemaIncludes:[Ljava.lang.String;@883540
[INFO] schemaExcludes:null
[INFO] bindingDirectory:D:\eclipse\pbona\workspace\tobias-ROOT\myapp\myapp-jaxb\src\main\xjc
[INFO] bindingIncludes:[Ljava.lang.String;@603c9f
[INFO] bindingExcludes:null
[INFO] disableDefaultExcludes:false
[INFO] catalog:D:\eclipse\pbona\workspace\tobias-ROOT\myapp\myapp-jaxb\src\main\xjc\catalog.cat
[INFO] catalogResolver:org.jvnet.jaxb2.maven2.resolver.tools.ClasspathCatalogResolver
[INFO] generatePackage:com.company.myapp.xjcctsamyapp
[INFO] generateDirectory:D:\eclipse\pbona\workspace\tobias-ROOT\myapp\myapp-jaxb\target\generated-sources\xjc
[INFO] readOnly:false
[INFO] extension:false
[INFO] strict:true
[INFO] writeCode:true
[INFO] verbose:true
[INFO] debug:false
[INFO] args:[-npa]
[INFO] forceRegenerate:true
[INFO] removeOldOutput:false
[INFO] otherDepends:null
[INFO] episodeFile:D:\eclipse\pbona\workspace\tobias-ROOT\myapp\myapp-jaxb\target\generated-sources\xjc\META-INF\sun-jaxb.episode
[INFO] episode:true
[INFO] classpathElements:[D:\eclipse\pbona\workspace\tobias-ROOT\myapp\myapp-jaxb\target\classes]
[INFO] plugins:[Lorg.apache.maven.model.Dependency;@2c14f9
[INFO] episodes:null
[INFO] xjcPlugins:[Lorg.apache.maven.model.Dependency;@2c14f9
[INFO] episodes:null
[INFO] specVersion:2.1
[INFO] schemaFiles (calculated):[D:\eclipse\pbona\workspace\tobias-ROOT\myapp\myapp-jaxb\src\main\resources\gws-ctsa-myapp.xsd]
[INFO] bindingFiles (calculated):[D:\eclipse\pbona\workspace\tobias-ROOT\myapp\myapp-jaxb\src\main\xjc\binding.xjb]
[INFO] xjcPluginArtifacts (resolved):[active project artifact:
artifact = com.company.common:common-jaxb:jar:1.0-SNAPSHOT:runtime;
project: MavenProject: com.company.common:common-jaxb:1.0-SNAPSHOT @ D:\eclipse\pbona\workspace\tobias-ROOT\common\common-jaxb\pom.xml]
[INFO] xjcPluginFiles (resolved):[D:\eclipse\pbona\workspace\tobias-ROOT\common\common-jaxb\target\classes]
[INFO] xjcPluginURLs (resolved):[file:/D:/eclipse/pbona/workspace/tobias-ROOT/common/common-jaxb/target/classes/]
[INFO] episodeArtifacts (resolved):[]
[INFO] episodeFiles (resolved):[]
[INFO] The schemaLanguage setting was not defined, assuming 'AUTODETECT'.
Using java.util.ServiceLoader
[INFO] Parsing input schema(s)...
[ERROR] Error while parsing schema(s).Location [ file:/D:/eclipse/pbona/workspace/tobias-ROOT/common/common-jaxb/target/classes/gws-service-types.xsd{14,35}].
org.xml.sax.SAXParseException: 'requiredString' is already defined
at com.sun.xml.xsom.impl.parser.ParserContext$1.reportError(ParserContext.java:176)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.reportError(NGCCRuntimeEx.java:170)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.reportError(NGCCRuntimeEx.java:173)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.checkDoubleDefError(NGCCRuntimeEx.java:145)
at com.sun.xml.xsom.impl.parser.state.Schema.action6(Schema.java:92)
at com.sun.xml.xsom.impl.parser.state.Schema.onChildCompleted(Schema.java:1176)
at com.sun.xml.xsom.impl.parser.state.NGCCHandler.revertToParentFromEnterElement(NGCCHandler.java:110)
at com.sun.xml.xsom.impl.parser.state.simpleType.enterElement(simpleType.java:130)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.startElement(NGCCRuntime.java:219)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
at com.sun.tools.xjc.util.SubtreeCutter.startElement(SubtreeCutter.java:104)
at com.sun.tools.xjc.reader.ExtensionBindingChecker.startElement(ExtensionBindingChecker.java:144)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
at com.sun.tools.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker.startElement(IncorrectNamespaceURIChecker.java:113)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.startElement(CustomizationContextChecker.java:188)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner$LocationResolver.startElement(DOMForestScanner.java:141)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:239)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:276)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:245)
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:122)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:89)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:97)
at com.sun.tools.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:99)
at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:262)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:337)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.importSchema(NGCCRuntimeEx.java:243)
at com.sun.xml.xsom.impl.parser.state.importDecl.action0(importDecl.java:45)
at com.sun.xml.xsom.impl.parser.state.importDecl.leaveElement(importDecl.java:138)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.endElement(NGCCRuntime.java:275)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:546)
at com.sun.tools.xjc.util.SubtreeCutter.endElement(SubtreeCutter.java:108)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:546)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:546)
at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.endElement(CustomizationContextChecker.java:194)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:546)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner$LocationResolver.endElement(DOMForestScanner.java:135)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:250)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:276)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:245)
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:122)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:89)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:97)
at com.sun.tools.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:99)
at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:262)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:337)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.importSchema(NGCCRuntimeEx.java:243)
at com.sun.xml.xsom.impl.parser.state.importDecl.action0(importDecl.java:45)
at com.sun.xml.xsom.impl.parser.state.importDecl.leaveElement(importDecl.java:138)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.endElement(NGCCRuntime.java:275)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:546)
at com.sun.tools.xjc.util.SubtreeCutter.endElement(SubtreeCutter.java:108)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:546)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:546)
at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.endElement(CustomizationContextChecker.java:194)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:546)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner$LocationResolver.endElement(DOMForestScanner.java:135)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:250)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:276)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:245)
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:122)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:89)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:97)
at com.sun.tools.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:99)
at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:262)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:337)
at com.sun.xml.xsom.impl.parser.ParserContext.parse(ParserContext.java:124)
at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:183)
at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:172)
at com.sun.tools.xjc.ModelLoader.createXSOM(ModelLoader.java:516)
at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:375)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:167)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:113)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.loadModel(RawXJC2Mojo.java:637)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:259)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:135)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
...
我在project_root / common / common-jaxb / pom.xml中使用命令“mvn compile”和以下插件配置:
<build>
<!-- *******************************************************************
* Plugins
******************************************************************* -->
<plugins>
<!-- Generieren -->
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
...
<!-- CTSA_MYAPP-->
<execution>
<id>gws-ctsa-myapp</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>gws-ctsa-myapp.xsd</include>
</schemaIncludes>
<generatePackage>com.company.myapp.xjcctsamyapp</generatePackage>
</configuration>
</execution>
</executions>
<!-- wir muessen dem Plugin noch sagen, wo die gws-service-types.xsd u.a. herkommt -->
<configuration>
<plugins>
<plugin>
<groupId>com.company.common</groupId>
<artifactId>common-jaxb</artifactId>
</plugin>
</plugins>
<catalogResolver>org.jvnet.jaxb2.maven2.resolver.tools.ClasspathCatalogResolver</catalogResolver>
<catalog>${xjc.resources.dir}/catalog.cat</catalog>
</configuration>
</plugin>
</plugins>
</build>
我尝试了很多更改和不同的配置,例如目录中的绝对路径(避免目录解析器),不同的命名空间和模式位置,并没有解决问题。有人有什么想法吗?
非常感谢提前!
佩德罗。
答案 0 :(得分:0)
我认为问题是由于使用了目录解析器。我不认为它是maven插件中的错误,这必须是JAXB-XJC中的内容。 我想请你准备一个演示/示例项目来重现这种行为(越小越好),并在JIRA中提交。 我将在下一个版本中解决这个问题。