Loy
Loy

Reputation: 143

Generate webservice via ant without eclipse

I'm trying to use ant to generate webservices from existing code to war file. Eclipse generate a complete ant buildfile (axis_bujava.xml) which works (but undeploy.wsdd is not generated all times, I don't know why) but only if I run it from eclipse.

I want to have a standalone script to generate my webservice (and after packaging it to warfile but this is not a problem ^^)

I added some jars from eclipse plugins folder to classpath and created the task "wsgen" but not I get a "null pointer exception".

My 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>

The error :

D:\Dev\S_Demo\ant\axis_bujava.xml:22: java.lang.NullPointerException at org.eclipse.wst.command.internal.env.context.PersistentContext.(PersistentContext.java:31) at org.eclipse.wst.command.internal.env.context.PersistentResourceContext.(PersistentResourceContext.java:36) at org.eclipse.wst.command.internal.env.context.PersistentResourceContext.getInstance(PersistentResourceContext.java:27) at org.eclipse.wst.command.internal.env.ant.AntController.(AntController.java:56) at ws.ant.task.WebServiceGenerationAntTask.execute(WebServiceGenerationAntTask.java:31) at 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) at java.lang.reflect.Method.invoke(Method.java:483) 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:435) at org.apache.tools.ant.Target.performTasks(Target.java:456) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393) at org.apache.tools.ant.Project.executeTarget(Project.java:1364) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1248) at org.apache.tools.ant.Main.runBuild(Main.java:851) at org.apache.tools.ant.Main.startAnt(Main.java:235) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 0 seconds

Upvotes: 1

Views: 1320

Answers (1)

Loy
Loy

Reputation: 143

As I said in comments, I solved this by using Axis class directly (as eclipse does) :

Important Note : Ant version used :

Apache Ant(TM) version 1.9.2 compiled on July 8 2013

1st, dependencies (minimal list, add them to ant classpath at execution) :

  • axis.jar
  • axis-ant.jar

2nd, Ant build.xml :

Get task from axis-ant.jar

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

In the target :

  1. generate wsdl file

Note : If not working, use org.apache.axis.wsdl.Java2WSDL, similar to next point and both have a "-h" option for help

<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. generate deploy/undeploy.wsdd files

Use of "java" directly because, in my case, ant task from axis-ant does not work. And exec task, I have some problems with java task (cause of ant version)

<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. Generate 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. Cleanup generated jar files

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

Upvotes: 3

Related Questions