通过ant生成web服务而不用eclipse

时间:2017-05-16 09:50:48

标签: java eclipse web-services ant wsdl

我尝试使用ant从现有代码生成web服务到war文件。 Eclipse生成一个完整的ant构建文件(axis_bujava.xml),它可以工作(但是并不总是生成undeploy.wsdd,我不知道为什么)但是只有我从eclipse运行它。

我想有一个独立的脚本来生成我的webservice(并在将它打包到warfile之后但是这不是问题^^)

我从eclipse插件文件夹中添加了一些jar到classpath并创建了任务" wsgen"但不是我得到一个"空指针异常"。

我的axis_bujava.xml:

<?xml version="1.0"?>

<project default="main" basedir=".">

<echo message="pulling in property files"/>
<property file="axis_bujava.properties"/>



<path id="wsgenlib">
      <fileset dir="${ant.library.dir}/org.eclipse.wst.command.env/" includes="ant-lib/anttasks.jar"/>
</path>

<taskdef name="wsgen"
         classname="ws.ant.task.WebServiceGenerationAntTask"
         classpath="${ant.library.dir}/org.eclipse.wst.command.env"
         />

<echo message="calling the web services generation ant task: axis_bujava"/>
 <target name="main" >

     <wsgen />
  </target>

</project>

错误:

  

D:\ Dev \ S_Demo \ ant \ axis_bujava.xml:22:java.lang.NullPointerException           在org.eclipse.wst.command.internal.env.context.PersistentContext。(PersistentContext.java:31)           在org.eclipse.wst.command.internal.env.context.PersistentResourceContext。(PersistentResourceContext.java:36)           at org.eclipse.wst.command.internal.env.context.PersistentResourceContext.getInstance(PersistentResourceContext.java:27)           在org.eclipse.wst.command.internal.env.ant.AntController。(AntController.java:56)           at ws.ant.task.WebServiceGenerationAntTask.execute(WebServiceGenerationAntTask.java:31)           在org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)           在java.lang.reflect.Method.invoke(Method.java:483)           在org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)           at org.apache.tools.ant.Task.perform(Task.java:348)           在org.apache.tools.ant.Target.execute(Target.java:435)           在org.apache.tools.ant.Target.performTasks(Target.java:456)           在org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)           在org.apache.tools.ant.Project.executeTarget(Project.java:1364)           at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)           在org.apache.tools.ant.Project.executeTargets(Project.java:1248)           在org.apache.tools.ant.Main.runBuild(Main.java:851)           在org.apache.tools.ant.Main.startAnt(Main.java:235)           在org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)           在org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

     

总时间:0秒

1 个答案:

答案 0 :(得分:3)

正如我在评论中所说,我通过直接使用Axis类解决了这个问题(就像eclipse那样):

重要提示:使用的Ant版本:

  

2013年7月8日编译的Apache Ant(TM)版本1.9.2

第1,依赖(最小列表,在执行时将它们添加到ant类路径):

  • axis.jar
  • 轴的ant.jar

2,Ant build.xml:

从axis-ant.jar获取任务

<taskdef 
        resource="axis-tasks.properties"
/>

在目标中:

  1. 生成wsdl文件
  2. 注意:如果不能正常工作,请使用org.apache.axis.wsdl.Java2WSDL,类似于下一点,两者都有一个&#34; -h&#34;帮助选项

    <axis-java2wsdl
            output="WebContent/WEB-INF/NameOf.wsdl"
            namespace="http://org.acme.com"
            style="WRAPPED"
            location="http://localhost/MyService/service/MyServiceImpl"
            classname="com.acme.org.MyServiceImpl"
            classpath="build/classes"
        /> 
    
    1. 生成deploy / undeploy.wsdd文件
    2. 使用&#34; java&#34;直接因为,在我的情况下,来自axis-ant的ant任务不起作用。和exec任务一样,我的java任务有一些问题(ant版本的原因)

      <exec executable="java">
          <arg value="-cp" />
          <arg value="${path.dependencies}/*;build/classes" />
          <arg value="org.apache.axis.wsdl.WSDL2Java" />
          <arg value="-d"/>
          <arg value="Application"/>
          <arg value="-o"/>
          <arg value="WebContent/WEB-INF/MyServiceImplService/"/>
          <arg value="-p"/>
          <arg value="com.acme.org"/>
          <arg value="-c"/>
          <arg value="com.acme.org.MyServiceImpl"/>
          <arg value="-s"/>
          <arg value="WebContent/WEB-INF/NameOf.wsdl"/>
      </exec>
      
      1. 生成server-config.wsdd

        <exec executable="java">
            <arg value="-cp" />
            <arg value="${path.dependencies}/*" />
            <arg value="org.apache.axis.utils.Admin" />
            <arg value="server"/>
            <arg value="WebContent/WEB-INF/MyServiceImplService/com.acme.org/deploy.wsdd"/>
        </exec>
        <move file="server-config.wsdd" tofile="WebContent/WEB-INF/server-config.wsdd"/>
        
      2. 清理生成的jar文件

        <delete>
            <fileset dir="WebContent/WEB-INF/MyServiceImplService/com.acme.org/" includes="*.java" />
        </delete>