2012-06-09 144 views
0

我有一個以下螞蟻腳本,我試圖調用axis2中提供的java2wsdl實用程序從編譯java類生成WSDL;axis2 java2wsdl在螞蟻目標

<exec executable="java2wsdl" newenvironment="false" dir="${build.ws.java.dir}" failonerror="true"> 
    <env key="AXIS2_HOME" value="${axis2.home.dir}" /> 
    <env key="CLASSPATH" value="${toString:compile.classpath}" /> 
    <env key="Path" value="${axis2.bin.dir}${path.separator}${env.Path}" /> 
    <env key="PATH" value="${axis2.bin.dir}${path.separator}${env.PATH}" /> 
    <arg line="-o ${build.ws.java.dir}${file.separator}wsdl" /> 
    <arg value="-cn ${trimmed.wsClass}" /> 
</exec> 

但是我在執行exec task中的java2wsdl時收到異常;

xbuild.xml:1141: Execute failed: java.io.IOException: Cannot run program "java2wsdl" (in directory "C:\RTC\sr 
c\Dev\Service\build\ws\java"): CreateProcess error=2, The system cannot find the file specified 
     at java.lang.ProcessBuilder.start(ProcessBuilder.java:459) 
     at java.lang.Runtime.exec(Runtime.java:593) 
     at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:862) 
     at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:481) 
     at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:495) 
     at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:631) 
     at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:672) 
     at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:498) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
     at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:197) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:154) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.Target.execute(Target.java:390) 
     at org.apache.tools.ant.Target.performTasks(Target.java:411) 
     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399) 
     at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38) 
     at org.apache.tools.ant.Project.executeTargets(Project.java:1251) 
     at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:442) 
     at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
     at net.sf.antcontrib.logic.ForEach.executeSequential(ForEach.java:178) 
     at net.sf.antcontrib.logic.ForEach.execute(ForEach.java:254) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.Target.execute(Target.java:390) 
     at org.apache.tools.ant.Target.performTasks(Target.java:411) 
     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399) 
     at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38) 
     at org.apache.tools.ant.Project.executeTargets(Project.java:1251) 
     at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:442) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
     at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:197) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:154) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.Target.execute(Target.java:390) 
     at org.apache.tools.ant.Target.performTasks(Target.java:411) 
     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399) 
     at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38) 
     at org.apache.tools.ant.Project.executeTargets(Project.java:1251) 
     at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:442) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
     at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:197) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:154) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
     at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:197) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:154) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
     at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:197) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:154) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398) 
     at net.sf.antcontrib.logic.ForTask.doSequentialIteration(ForTask.java:259) 
     at net.sf.antcontrib.logic.ForTask.doToken(ForTask.java:268) 
     at net.sf.antcontrib.logic.ForTask.doTheTasks(ForTask.java:299) 
     at net.sf.antcontrib.logic.ForTask.execute(ForTask.java:244) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398) 
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
     at org.apache.tools.ant.Task.perform(Task.java:348) 
     at org.apache.tools.ant.Target.execute(Target.java:390) 
     at org.apache.tools.ant.Target.performTasks(Target.java:411) 
     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399) 
     at org.apache.tools.ant.Project.executeTarget(Project.java:1368) 
     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:809) 
     at org.apache.tools.ant.Main.startAnt(Main.java:217) 
     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) 
     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109) 
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified 
     at java.lang.ProcessImpl.create(Native Method) 
     at java.lang.ProcessImpl.<init>(ProcessImpl.java:81) 
     at java.lang.ProcessImpl.start(ProcessImpl.java:30) 
     at java.lang.ProcessBuilder.start(ProcessBuilder.java:452) 
     ... 185 more  

什麼是缺失?

感謝

-

SJunejo

+0

你的一個文件路徑。我建議在調試模式下運行ANT並檢查傳遞給Java任務的命令行。 –

+0

剛剛嘗試過,一切似乎都正常。 PATH,CLASSPATH和AXIS_HOME全部設置:( – SJunejo

回答

0

我發現有以下鏈接的幫助下解決;

http://axis.apache.org/axis2/java/core/tools/CodegenToolReference.html

參考部 '調用代碼生成器從螞蟻'。

以上任務定義了wsdl2java。我正在提供java2wsdl,以供將來參考;

<target name="java-to-wsdl" unless="wsdl.generated" description="This target will generate actual WSDL file for each WS class provided" > 
    <!-- Prepare classpath --> 
    <path id="axis2.classpath"> 
     <!-- Add Axis2 Libraries --> 
     <fileset dir="${axis2.lib.dir}" includes="**/*.jar" /> 
     <!-- Java WS Build Directory --> 
     <dirset dir="${build.ws.java.dir}" /> 
     <!-- Full compile classpath for data and rest of other classes --> 
     <path refid="compile.classpath" /> 
    </path> 
    <!-- Convert java ws class path into a fully qualified name i.e. com.temenos.webservices.[service_name].[service_wsClassName] --> 
    <path id="java.ws.class" > 
     <fileset file="${wsClassfile}" /> 
    </path> 
    <pathconvert property="trimmed.wsClass" refid="java.ws.class" > 
     <packagemapper from="${build.ws.java.dir}${file.separator}*.class" to="*"/> 
    </pathconvert> 
    <if> 
     <not> 
      <equals arg1="${trimmed.wsClass}" arg2="" /> 
     </not> 
     <then> 
      <property name="axis2.home" value="${axis2.bin.dir}" /> 
      <java classname="org.apache.ws.java2wsdl.Java2WSDL" fork="yes" failonerror="true" > 
       <classpath refid="axis2.classpath"/> 
       <arg value="-o"/> 
       <arg value="${build.ws.java.dir}${file.separator}wsdl"/> 
       <arg value="-cn"/> 
       <arg value="${trimmed.wsClass}"/> 
      </java> 
     </then> 
    </if> 
    <property name="wsdl.generated" value="true" /> 
</target> 

注意:對於在ANT執行.BAT或.sh原來的問題,即不允許作爲僅對可執行。如果您必須使用這些腳本,則使用ant-contrib任務。

感謝

-

Sjunejo

0

我可以看到很多的代碼,但我沒有看到實際的螞蟻任務被調用。 我的解決方案擁有這樣的代碼:

定義:

<taskdef name="axis2-wsdl2java" classname="org.apache.axis2.tool.ant.AntCodegenTask"> 
<classpath> 
    <fileset dir="some axis2 lib folder/axis2-1.4.1/lib" includes="*.jar" /> 
</classpath> 

用法:

<target name="main" description="Generate" depends="init"> 
<echo message="Uri is ${uri}" /> 
<echo message="Generation output-folder set to ${output_folder}" /> 
<delete dir="${output_folder}" /> 
<mkdir dir="${output_folder}" /> 

<axis2-wsdl2java wsdlfilename="${uri}" output="${output_folder}" /> 
<ant dir="${output_folder}" /> 
<runtarget target="determine_jarname" /> 
<echo message="in main jar_filename set to ${jar_filename}" /> 
<jar destfile="${jar_output_folder}/${jar_filename}.jar" 
     basedir="${output_folder}/build/classes" /> 

所以要WSDL2Java的實際調用是一個線

<axis2-wsdl2java wsdlfilename="${uri}" output="${output_folder}" /> 

的另一件事是設置屬性$ {} env.AXIS2_HOME以及不正確的

+0

我的猜測是** paul

+0

我現在看到我的例子是用於WSDL2java,但也有一個java2WSDL任務 ([任務文檔在這裏](http://axis.apache.org/axis/java/ant/axis-java2wsdl.html)),我認爲它的工作原理類似 – Niek