导入命名空间 - 无法将名称解析为(n)'类型定义'组件 [英] Import namespace - Cannot resolve the name to a(n) 'type definition' component
问题描述
上下文:我使用maven-jaxb插件从xsd文件生成java类。我的所有.xsd文件都在一个位置 - src / main / resource目录。
Context: I am generating java classes from xsd files using maven-jaxb plugin. All my .xsd files are in a single location - src/main/resource directory.
问题:当xsd没有引用/导入具有不同目标命名空间的其他xsd时,一切正常。但是当下面的xsd(使用targetNamespace =http://www.companyA.com/someservice)从另一个命名空间(namespace =http://www.companyB.com/)导入另一个xsd filename.xsd时,我得到上面的错误:无法将名称xxx解析为(n)'类型定义'组件。
Problem: Everything works fine when xsd's don't reference/import other xsd's with a different target namespace. However when the following xsd below (with targetNamespace="http://www.companyA.com/someservice") imports another xsd filename.xsd from a different namespace (namespace="http://www.companyB.com/"), I get the above error: Cannot resolve the name xxx to a(n) 'type definition' component.
编辑:当前xsd文件中的元素名称是' entityName',它的类型是companyB:entityName(即)名称是相同的。
the element name in the current xsd file is 'entityName', and its type is "companyB:entityName" (i.e.) the names are the same.
然后我尝试从命令行调用此文件上的xjc正确生成Java类。我还确保在Eclipse中,我可以在type =companyCdm:entityName上按住Ctrl键单击/检查源代码,它正确地打开了filename.xsd文件。但是由于某些原因,maven无法访问它。
I then tried invoking xjc on this file from the command line and this generated Java classes correctly. I also made sure that in Eclipse, I am able to ctrl-click/examine source on "type="companyCdm:entityName", which correctly opens the filename.xsd file. However for some reason maven is unable to get to it.
问题:我缺少什么?为什么这种情况(2个名称空间)与处理单个名称空间不同?
Question: What am I missing? Why is this case (2 namespaces) different from dealing with a single namespace?
这是我的XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.companyA.com/someservice"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:companyB="http://www.companyB.com/version"
targetNamespace="http://www.companyA.com/someservice"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xsd:import namespace="http://www.companyB.com/version" schemaLocation="filename.xsd" />
<xsd:element name="MyName" type="MyType" />
<xsd:complexType name="MyType">
<xsd:annotation>
<xsd:documentation>
A list
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="entityName" type="companyB:entityName" maxOccurs="1" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
推荐答案
好的找到了解决办法:
我将所有依赖的xsd(有问题的xsd的引用)加上一堆其他未使用的xsd移动到一个单独的文件夹然后使用maven重新生成代码 - 它现在可以工作了。似乎存在一些与其他未使用的xsd之一的名称空间冲突,我还没有指出具体的那个。
I moved all the dependent xsd's (that the problematic xsd's references) plus a bunch of other un-used xsds to a separate folder and then re-generated code using maven - it works now. It appears that there was some namespace conflict with one of the other un-used xsd's i haven't yet pointed out the specific one.
这篇关于导入命名空间 - 无法将名称解析为(n)'类型定义'组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!