2012-06-09 95 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