我收到了wsdl+xsd文件,我尝试生成java类,因为我已经做了很多次了,但是这次我遇到了问题。我使用的是ApacheMaven3.2.5
我用的是maven插件
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>wsimport-id</id>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>${project.basedir}/src/main/resources/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>UtilService_1.wsdl</wsdlFile>
</wsdlFiles>
<keep>true</keep>
<sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
</configuration>
</plugin>
我收到一个例外
[INFO] jaxws:wsimport args: [-keep, -s, 'C:\Users\john\GIT\test-projectt\target\generated-sources\jaxws-wsimport', -d, 'C:\Users\john\GIT\test-projectt\target\classes', -encoding, UTF-8, -Xnocompile, "file:/C:/Users/john/GIT/test-projectt/src/main/resources/wsdl/UtilService_1.wsdl"]
parsing WSDL...
[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 65 of file:/C:/Users/john/GIT/test-projectt/src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18.xsd
[ERROR] (Related to above error) This is the other declaration.
line 86 of file:/C:/Users/john/GIT/test-projectt/src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18.xsd
[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 87 of file:/C:/Users/john/GIT/test-projectt/src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18.xsd
[ERROR] (Related to above error) This is the other declaration.
line 90 of file:/C:/Users/john/GIT/test-projectt/src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18.xsd
[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 34 of file:/C:/Users/john/GIT/test-projectt/src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18.xsd
[ERROR] (Related to above error) This is the other declaration.
line 38 of file:/C:/Users/john/GIT/test-projectt/src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18.xsd
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.jaxws.Invoker.main(Invoker.java:80)
Caused by: com.sun.tools.ws.wscompile.AbortException
at com.sun.tools.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:114)
at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.buildJAXBModel(WSDLModeler.java:2268)
at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.internalBuildModel(WSDLModeler.java:168)
at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.buildModel(WSDLModeler.java:111)
at com.sun.tools.ws.wscompile.WsimportTool.buildWsdlModel(WsimportTool.java:414)
at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:175)
at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:153)
... 5 more
所以我添加了bindings.xml
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0">
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.0"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.1"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.2"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.3"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.4"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.5"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.6"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.7"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.8"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.9"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.10"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.11"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.12"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.13"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.14"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.15"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.16"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.17"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.18"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.19"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.20"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.21"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.22"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.23"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.24"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.25"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.26"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.27"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.28"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.29"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.30"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.31"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.32"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.33"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.34"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.35"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.36"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.37"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.38"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.39"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39_40.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.40"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39_40_41.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.41"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39_40_41_42.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.42"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39_40_41_42_43.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.43"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39_40_41_42_43_44.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.44"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39_40_41_42_43_44_45.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.45"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39_40_41_42_43_44_45_46.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.46"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39_40_41_42_43_44_45_46_47.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.47"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="src/main/resources/wsdl/UtilService_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39_40_41_42_43_44_45_46_47_48.xsd">
<jaxb:schemaBindings>
<jaxb:package name="com.test.48"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
改变了maven插件的定义
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>wsimport-id</id>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-b bindings.xml</arg>
</args>
<wsdlDirectory>${project.basedir}/src/main/resources/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>UtilService_1.wsdl</wsdlFile>
</wsdlFiles>
<keep>true</keep>
<bindingDirectory>${project.basedir}/src/main/resources/wsdl/bindings</bindingDirectory>
<sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
</configuration>
</plugin>
不幸的是仍然没有成功。我做错什么了?wsdl和xsd文件中有很多嵌套元素。不幸的是,我不能改变它,我从供应商那里得到了这些文件,我必须以它们为基础
[INFO] --- jaxws-maven-plugin:2.6:wsimport (wsimport-id) @ test-projectt ---
[INFO] Processing: file:/C:/Users/john/GIT/test-projectt/src/main/resources/wsdl/UtilService_1.wsdl
[INFO] jaxws:wsimport args: [-keep, -s, 'C:\Users\john\GIT\test-projectt\target\generated-sources\jaxws-wsimport', -d, 'C:\Users\john\GIT\test-projectt\target\classes', -encoding, UTF-8, -Xnocompile, -b bindings.xml, -b, 'file:/C:/Users/john/GIT/test-projectt/src/main/resources/wsdl/bindings/bindings.xml', "file:/C:/Users/john/GIT/test-projectt/src/main/resources/wsdl/UtilService_1.wsdl"]
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.jaxws.Invoker.main(Invoker.java:80)
Exception: java.lang.NoClassDefFoundError thrown from the UncaughtExceptionHandler in thread "main"
暂无答案!
目前还没有任何答案,快来回答吧!