我在Java项目中使用wsimport来生成三个SOAP Web服务的源代码。前两个工作正常:我使用JAX-WS Maven插件来获取WSDL文件并生成相应的Java源文件。
一个Web服务失败;我收到以下错误:
[jaxws:wsimport]
Processing: /home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
jaxws:wsimport args: [-s, /home/me/NetBeansProjects/Admin/AdminWeb/target/generated-sources/jaxws-wsimport, -d, /home/me/NetBeansProjects/Admin/AdminWeb/target/classes, -verbose, -catalog, /home/me/NetBeansProjects/Admin/AdminWeb/src/jax-ws-catalog.xml, -wsdllocation, http://erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx?WSDL, -target, 2.0, -extension, -Xnocompile, /home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl]
parsing WSDL...
src-resolve.4.2: Error resolving component 's:schema'. It was detected that 's:schema' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl#types?schema1'. If this is the incorrect namespace, perhaps the prefix of 's:schema' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl#types?schema1'.
line 80 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl#types?schema1
undefined element declaration 's:schema'
line 80 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
undefined element declaration 's:schema'
line 127 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
undefined element declaration 's:schema'
line 142 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
<小时/>
此WSDL文件与有效的文件之间的区别在于错误消息中第80,127和142行中注明的行:
<s:element ref="s:schema" />
注意:wsdl文件的根元素因此定义了“s”命名空间:
xmlns:s="http://www.w3.org/2001/XMLSchema"
<小时/>
我完成了我的研究。看起来其他人也有类似的问题,解决方案从“只是不使用<s:element ref="s:schema" />
”到“使用导入标签”,到一些不可知的解决方案,显然是在旧的java.net论坛上(之前)它被拆除,是现代亚历山大Java知识库的一个纵火。)
我尝试将以下import语句放在包含问题标记的元素中:<s:import namespace="http://www.w3.org/2001/XMLSchema" schemaLocation="http://www.w3.org/2001/XMLSchema.xsd" />
。 wsimport给了我一个新的错误:
[jaxws:wsimport]
Processing: /home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
jaxws:wsimport args: [-s, /home/me/NetBeansProjects/Admin/AdminWeb/target/generated-sources/jaxws-wsimport, -d, /home/me/NetBeansProjects/Admin/AdminWeb/target/classes, -verbose, -catalog, /home/me/NetBeansProjects/Admin/AdminWeb/src/jax-ws-catalog.xml, -wsdllocation, http://erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx?WSDL, -target, 2.0, -extension, -Xnocompile, /home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl]
parsing WSDL...
Element "{http://www.w3.org/2001/XMLSchema}annotation" shows up in more than one properties.
line 248 of http://www.w3.org/2001/XMLSchema.xsd
The following location is relevant to the above error
line 242 of http://www.w3.org/2001/XMLSchema.xsd
Property "Any" is already defined. Use <jaxb:property> to resolve this conflict.
line 108 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
The following location is relevant to the above error
line 109 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
Property "Any" is already defined. Use <jaxb:property> to resolve this conflict.
line 184 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
The following location is relevant to the above error
line 185 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
Property "Any" is already defined. Use <jaxb:property> to resolve this conflict.
line 199 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
The following location is relevant to the above error
line 200 of file:/home/me/NetBeansProjects/Admin/AdminWeb/src/wsdl/erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl
此错误中引用的第108和109行是:(第184-5,199-200行相似)
<s:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax" />
<s:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax" />
我尝试将jaxws-maven-plugin从1.10升级到2.2。同样的问题。
<小时/>
有什么想法吗?您需要的任何进一步信息?为简洁起见,我省略了pom.xml和Service.asmx.wsdl文件,但如果其中包含更多重要信息,则可以包含它们。
谢谢!
Here's another person having the same problem,如果这有助于任何潜在的回答者。 Here's yet another similar problem. 我真的不明白this article,但似乎暗示我必须手动解析SOAP XML!恐怖!
答案 0 :(得分:15)
我通过调整Vivek Pandey's method到Maven,同时更新到jaxws-maven-plugin 2.2来解决这个问题。我会在这里重申它的后代:
将this XJB customization file(见下文)放在默认的绑定文件目录中,并设置wsimport将其绑定到http://www.w3.org/2001/XMLSchema.xsd。
前面提到的XML文件xsd.xjb的内容应该放在你的默认绑定文件目录中,如下所示(归功于Kohsuke):
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
version="2.0">
<globalBindings>
<xjc:simple />
</globalBindings>
<bindings scd="~xsd:complexType">
<class name="ComplexTypeType"/>
</bindings>
<bindings scd="~xsd:simpleType">
<class name="SimpleTypeType"/>
</bindings>
<bindings scd="~xsd:group">
<class name="GroupType"/>
</bindings>
<bindings scd="~xsd:attributeGroup">
<class name="AttributeGroupType"/>
</bindings>
<bindings scd="~xsd:element">
<class name="ElementType"/>
</bindings>
<bindings scd="~xsd:attribute">
<class name="attributeType"/>
</bindings>
</bindings>
以下是我的POM文件的相关部分,其中包含更改:
<plugin>
<!-- CHANGE: updated groupId and version -->
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<!-- CHANGE: added args tag to bind http://www.w3.org/2001/XMLSchema.xsd -->
<args>
<arg>-b</arg><arg>http://www.w3.org/2001/XMLSchema.xsd</arg>
</args>
<wsdlFiles>
<wsdlFile>erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>http://erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl</wsdlLocation>
<staleFile>${project.build.directory}/jaxws/stale/Service.asmx.stale</staleFile>
<!-- CHANGE: added bindingFiles tag to bind XJB customization, located at the default binding files directory, MyProject/src/jaxws/xsd.xjb . -->
<bindingFiles>
<bindingFile>xsd.xjb</bindingFile>
</bindingFiles>
</configuration>
<id>wsimport-generate-egtestreportengine</id>
<phase>generate-sources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>webservices-api</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<configuration>
<sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
<xnocompile>true</xnocompile>
<verbose>true</verbose>
<extension>true</extension>
<catalog>${basedir}/src/jax-ws-catalog.xml</catalog>
<target>2.0</target>
</configuration>
</plugin>
答案 1 :(得分:7)
对于Nick的解决方案,你可能需要将这两个jvm参数添加到你的pom.xml中 所以当遇到这些错误时:
org.xml.sax.SAXParseException; systemId:http://www.w3.org/2001/XMLSchema.xsd; lineNumber:67; columnNumber:11;外部DTD:无法读取外部DTD&#39; XMLSchema.dtd&#39;,因为&#39; http&#39;由于accessExternalDTD属性设置的限制,不允许访问。
[警告] schema_reference:无法读取架构文档&#39; xml.xsd&#39;,因为&#39; http&#39;由于accessExternalSchema属性设置的限制,不允许访问。 http://www.w3.org/2001/XMLSchema.xsd
的第91行
只需将它们添加到您的pom.xml
即可-Djavax.xml.accessExternalDTD=all
-Djavax.xml.accessExternalSchema=all
<vmArgs>
<vmArg>-Djavax.xml.accessExternalDTD=all</vmArg>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
答案 2 :(得分:1)
如果您实际上并不关心模型数据的这一特定位,您可以使用JAXB绑定文件来告诉JAXB将有问题的位映射到类型为DOM Element
的属性,而不是实际上尝试将数据绑定到普通的JAXB类中。 unofficial JAXB guide有一个关于这种技术的部分。
答案 3 :(得分:1)
如果同样的问题用以下命令修复它:
wsimport -b http://www.w3.org/2001/XMLSchema.xsd -b xsd.xjb service.wsdl
xsd.xjb
指的是:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
version="2.0">
<globalBindings>
<xjc:simple />
</globalBindings>
<bindings scd="~xsd:complexType">
<class name="ComplexTypeType"/>
</bindings>
<bindings scd="~xsd:simpleType">
<class name="SimpleTypeType"/>
</bindings>
<bindings scd="~xsd:group">
<class name="GroupType"/>
</bindings>
<bindings scd="~xsd:attributeGroup">
<class name="AttributeGroupType"/>
</bindings>
<bindings scd="~xsd:element">
<class name="ElementType"/>
</bindings>
<bindings scd="~xsd:attribute">
<class name="attributeType"/>
</bindings>
</bindings>
答案 4 :(得分:0)
这似乎最终对我有用。我正在使用apache maven cfx插件
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<additionalJvmArgs>
-Djavax.xml.accessExternalDTD=all
</additionalJvmArgs>
<sourceRoot>${basedir}/src/main/generated</sourceRoot>
<wsdlOptions>
<wsdlOption>
<extraargs>
<extraarg>-autoNameResolution</extraarg>
<extraarg>-impl</extraarg>
<extraarg>-verbose</extraarg>
<extraarg>-b</extraarg>
<extraarg>http://www.w3.org/2001/XMLSchema.xsd</extraarg>
<extraarg>-p</extraarg>
<extraarg>com.nevado.travelstudio</extraarg>
</extraargs>
<!-- <bindingFiles> <bindingFile>${basedir}/src/main/resources/wsdl/mybindings.xjb</bindingFile>
</bindingFiles> -->
<wsdl>${basedir}/src/main/resources/wsdl/B2.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
以及这些更改我必须在..java / jdk / jre / lib文件夹中创建 jaxp.properties 文件 具有以下属性
-Djavax.xml.accessExternalDTD=all