title: Getting java.lang.reflect.InvocationTargetException in Ant Script for WsImport
body: <p>I am trying to use WSImport2 to create some bean classes from wsdl files. But I get the errors</p>
  
  <pre><code>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.&lt;init&gt;(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.&lt;init&gt;(ColorBinder.java:62)
          at com.sun.tools.xjc.reader.xmlschema.BindGreen.&lt;init&gt;(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.&lt;init&gt;(Adapter.java:88)
          at com.sun.tools.xjc.model.CAdapter.&lt;init&gt;(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.&lt;clinit&gt;(CBuiltinLeafInfo.java:387)
          at com.sun.tools.xjc.reader.xmlschema.SimpleTypeBuilder.&lt;clinit&gt;(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.&lt;init&gt;(DefaultClassBinder.java:98)
          at com.sun.tools.xjc.reader.xmlschema.ClassSelector.&lt;init&gt;(ClassSelector.java:214)
          ... 59 more
  
  Total time: 11 seconds
  </code></pre>
  
  <p>There are a lot more lines in the stack trace. If needed I will upload it. I have most of the JAX jars in my classpath.</p>
  
  <p>The line causing the problem, is:</p>
  
  <pre><code>&lt;wsimport wsdl="${build.dir}/src/${wsdl.file}" destdir="build" wsdlLocation="file:/WEB-INF/wsdl/${wsdl.file}" failonerror="true" verbose="true"&gt;
          &lt;depends dir="${build.dir}/src" includes="*.xsd" /&gt; 
          &lt;produces dir="${lib.dir}" includes="${webservice.name}${webservice.component}WSBeans.jar"/&gt;
      &lt;/wsimport&gt;
  </code></pre>
  
  <p>I am having issues uploading the whole stack trace, but I am only filling this section up to make the question post!</p>