在 WsImport 的 Ant 脚本中获取 java.lang.reflect.InvocationTargetException
Getting java.lang.reflect.InvocationTargetException in Ant Script for WsImport
我正在尝试使用 WSImport2 从 wsdl 文件创建一些 bean 类。但是我得到了错误
H:\Workspace\common-build.xml:745: java.lang.Error: java.lang.reflect.InvocationTargetException
at com.sun.tools.xjc.reader.Ring.get(Ring.java:113)
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.<init>(BGMBuilder.java:147)
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.build(BGMBuilder.java:117)
at com.sun.tools.xjc.ModelLoader.annotateXMLSchema(ModelLoader.java:425)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:277)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:95)
at com.sun.tools.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:112)
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)
at com.sun.tools.ws.ant.WsImportBase.runInVm(WsImportBase.java:569)
at com.sun.tools.ws.ant.WsTask2.execute(WsTask2.java:457)
at com.sun.tools.ws.ant.WsImportBase.execute(WsImportBase.java:552)
at com.sun.tools.ws.ant.WsImport2.execute(WsImport2.java:23)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:36)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:437)
at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:306)
at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:225)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:834)
at org.apache.tools.ant.Main.startAnt(Main.java:223)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.sun.tools.xjc.reader.Ring.get(Ring.java:102)
... 46 more
Caused by: java.lang.Error: java.lang.reflect.InvocationTargetException
at com.sun.tools.xjc.reader.Ring.get(Ring.java:113)
at com.sun.tools.xjc.reader.xmlschema.BindingComponent.getClassSelector(BindingComponent.java:65)
at com.sun.tools.xjc.reader.xmlschema.ColorBinder.<init>(ColorBinder.java:62)
at com.sun.tools.xjc.reader.xmlschema.BindGreen.<init>(BindGreen.java:63)
... 51 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.sun.tools.xjc.reader.Ring.get(Ring.java:102)
... 54 more
Caused by: java.lang.NoSuchFieldError: REFLECTION
at com.sun.tools.xjc.model.nav.NavigatorImpl.getBaseClass(NavigatorImpl.java:74)
at com.sun.tools.xjc.model.nav.NavigatorImpl.getBaseClass(NavigatorImpl.java:59)
at com.sun.xml.bind.v2.model.core.Adapter.<init>(Adapter.java:88)
at com.sun.tools.xjc.model.CAdapter.<init>(CAdapter.java:82)
at com.sun.tools.xjc.model.TypeUseFactory.adapt(TypeUseFactory.java:95)
at com.sun.tools.xjc.model.CBuiltinLeafInfo.makeAdapted(CBuiltinLeafInfo.java:192)
at com.sun.tools.xjc.model.CBuiltinLeafInfo.<clinit>(CBuiltinLeafInfo.java:387)
at com.sun.tools.xjc.reader.xmlschema.SimpleTypeBuilder.<clinit>(SimpleTypeBuilder.java:897)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.sun.tools.xjc.reader.Ring.get(Ring.java:102)
at com.sun.tools.xjc.reader.xmlschema.DefaultClassBinder.<init>(DefaultClassBinder.java:98)
at com.sun.tools.xjc.reader.xmlschema.ClassSelector.<init>(ClassSelector.java:214)
... 59 more
Total time: 11 seconds
堆栈跟踪中有更多行。如果需要我会上传它。我的类路径中有大部分 JAX jar。
引起问题的行是:
<wsimport wsdl="${build.dir}/src/${wsdl.file}" destdir="build" wsdlLocation="file:/WEB-INF/wsdl/${wsdl.file}" failonerror="true" verbose="true">
<depends dir="${build.dir}/src" includes="*.xsd" />
<produces dir="${lib.dir}" includes="${webservice.name}${webservice.component}WSBeans.jar"/>
</wsimport>
我在上传整个堆栈跟踪时遇到问题,但我只是填写此部分来提出问题 post!
原来是JAXB XJC jar版本不匹配。它与 JAXB Impl 和 Core jar 不匹配。
这两个罐子是:
jaxb-core-2.3.0.1.jar
jaxb-impl-2.3.0.1.jar
虽然我的 XJC 是:
jaxb-xjc-2.2.7
升级到相同版本,现在可以正常使用了。
我正在尝试使用 WSImport2 从 wsdl 文件创建一些 bean 类。但是我得到了错误
H:\Workspace\common-build.xml:745: java.lang.Error: java.lang.reflect.InvocationTargetException
at com.sun.tools.xjc.reader.Ring.get(Ring.java:113)
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.<init>(BGMBuilder.java:147)
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.build(BGMBuilder.java:117)
at com.sun.tools.xjc.ModelLoader.annotateXMLSchema(ModelLoader.java:425)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:277)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:95)
at com.sun.tools.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:112)
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)
at com.sun.tools.ws.ant.WsImportBase.runInVm(WsImportBase.java:569)
at com.sun.tools.ws.ant.WsTask2.execute(WsTask2.java:457)
at com.sun.tools.ws.ant.WsImportBase.execute(WsImportBase.java:552)
at com.sun.tools.ws.ant.WsImport2.execute(WsImport2.java:23)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:36)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:437)
at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:306)
at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:225)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:834)
at org.apache.tools.ant.Main.startAnt(Main.java:223)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.sun.tools.xjc.reader.Ring.get(Ring.java:102)
... 46 more
Caused by: java.lang.Error: java.lang.reflect.InvocationTargetException
at com.sun.tools.xjc.reader.Ring.get(Ring.java:113)
at com.sun.tools.xjc.reader.xmlschema.BindingComponent.getClassSelector(BindingComponent.java:65)
at com.sun.tools.xjc.reader.xmlschema.ColorBinder.<init>(ColorBinder.java:62)
at com.sun.tools.xjc.reader.xmlschema.BindGreen.<init>(BindGreen.java:63)
... 51 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.sun.tools.xjc.reader.Ring.get(Ring.java:102)
... 54 more
Caused by: java.lang.NoSuchFieldError: REFLECTION
at com.sun.tools.xjc.model.nav.NavigatorImpl.getBaseClass(NavigatorImpl.java:74)
at com.sun.tools.xjc.model.nav.NavigatorImpl.getBaseClass(NavigatorImpl.java:59)
at com.sun.xml.bind.v2.model.core.Adapter.<init>(Adapter.java:88)
at com.sun.tools.xjc.model.CAdapter.<init>(CAdapter.java:82)
at com.sun.tools.xjc.model.TypeUseFactory.adapt(TypeUseFactory.java:95)
at com.sun.tools.xjc.model.CBuiltinLeafInfo.makeAdapted(CBuiltinLeafInfo.java:192)
at com.sun.tools.xjc.model.CBuiltinLeafInfo.<clinit>(CBuiltinLeafInfo.java:387)
at com.sun.tools.xjc.reader.xmlschema.SimpleTypeBuilder.<clinit>(SimpleTypeBuilder.java:897)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.sun.tools.xjc.reader.Ring.get(Ring.java:102)
at com.sun.tools.xjc.reader.xmlschema.DefaultClassBinder.<init>(DefaultClassBinder.java:98)
at com.sun.tools.xjc.reader.xmlschema.ClassSelector.<init>(ClassSelector.java:214)
... 59 more
Total time: 11 seconds
堆栈跟踪中有更多行。如果需要我会上传它。我的类路径中有大部分 JAX jar。
引起问题的行是:
<wsimport wsdl="${build.dir}/src/${wsdl.file}" destdir="build" wsdlLocation="file:/WEB-INF/wsdl/${wsdl.file}" failonerror="true" verbose="true">
<depends dir="${build.dir}/src" includes="*.xsd" />
<produces dir="${lib.dir}" includes="${webservice.name}${webservice.component}WSBeans.jar"/>
</wsimport>
我在上传整个堆栈跟踪时遇到问题,但我只是填写此部分来提出问题 post!
原来是JAXB XJC jar版本不匹配。它与 JAXB Impl 和 Core jar 不匹配。
这两个罐子是:
jaxb-core-2.3.0.1.jar
jaxb-impl-2.3.0.1.jar
虽然我的 XJC 是:
jaxb-xjc-2.2.7
升级到相同版本,现在可以正常使用了。