---
title: "webservice开发和使用指南5"
author: "charles751"
date: "2008-09-22T17:18:18Z"
tags: ["Ant", "Apache", "EJB", "WebService", "XML"]
slug: "webservice-5"
draft: false
lastmod: "2008-09-22T17:18:18Z"
id: 245528
url: "https://qify.iteye.com/blog/245528"
---

**14.2       build.xml脚本代码**

在这里增加了详细的注释。基本覆盖了axis全部使用方式。

&lt;?xml version="1.0" ?&gt;

&lt;!DOCTYPE project [

        &lt;!ENTITY properties SYSTEM "file:../xmls/properties.xml"&gt;

        &lt;!ENTITY paths SYSTEM "file:../xmls/path\_refs.xml"&gt;

        &lt;!ENTITY taskdefs SYSTEM "file:../xmls/taskdefs.xml"&gt;

        &lt;!ENTITY taskdefs\_post\_compile SYSTEM "file:../xmls/taskdefs\_post\_compile.xml"&gt;

        &lt;!ENTITY targets SYSTEM "file:../xmls/targets.xml"&gt;

]&gt;

 

&lt;!-- ===================================================================

&lt;description&gt;

   Component file for Axis

Notes:

   This is a build file for use with the Jakarta Ant build tool.

Prerequisites:

   jakarta-ant from http://jakarta.apache.org

Build Instructions:

   To wsdl2java

        ant wsdl2java

Author:

   lanning thunder4393@gmail.com zhanglelei@channelsoft.com

 

Copyright:

 Copyright (c) 2002-2003 Apache Software Foundation.

&lt;/description&gt;

==================================================================== --&gt;

&lt;!-- ====================================================================

    1. You may use service interface to generate wsdl and other code files with &lt;target name="java2wsd"&gt;

    2. You also may use wsdl to generate code files and wsdd file with &lt;target name="java2wsd"&gt;

    ====================================================================

--&gt;

&lt;!-- basedir is a build-in properties, it may directly be ${basedir}--&gt;

&lt;project default="wsdl2java" basedir="." &gt;

 

&lt;property name="axis.home" location=".." /&gt;

   

&lt;property name="app.name" value="axis" /&gt;

   

&lt;property name="componentName" value="com/int97" /&gt;

 

&lt;property name="dev.dir" location="${basedir}" /&gt;

 

&lt;property name="dev.classes.dir" location="${axis.home}/webapps/axis/WEB-INF/classes" /&gt;

 

&lt;path id="dev.classpath"&gt;

    &lt;pathelement path="${dev.classes.dir}"/&gt;

&lt;/path&gt;

 

&lt;path id="axis.classpath"&gt;

    &lt;fileset dir="${axis.home}/webapps/axis/WEB-INF/lib"&gt;

       &lt;include name="\*\*/\*.jar" /&gt;

    &lt;/fileset&gt;

&lt;/path&gt;   

   

&lt;path id="all.classpath"&gt;

    &lt;path refid="axis.classpath"/&gt;

    &lt;pathelement location="${dev.classes.dir}" /&gt;

&lt;/path&gt;   

 

&lt;!-- the &lt;taskdef&gt; declaration to declare all the tasks listed in a properties file

     inside the axis-ant.jar file 

     other definition method:

          &lt;taskdef name="axis-java2wsdl" classname="org.apache.axis.tools.ant.wsdl.Java2WsdlAntTask"

           loaderref="axis" &gt;

               &lt;classpath refid="classpath.id"/&gt;

        &lt;/taskdef&gt;

--&gt;

&lt;taskdef resource="axis-tasks.properties" classpathref="axis.classpath" /&gt;

 

        &properties;

        &paths;

        &taskdefs;

        &taskdefs\_post\_compile;

        &targets;

 

&lt;target name="clean"/&gt;

 

&lt;target name="copy" depends="setenv"/&gt;

   

&lt;!-- =================================================================== --&gt;

&lt;!-- Set relevant parameters for concrete application

     for example:

        1. set wsdl file name

        2. set mapping's package name

        3. wsdl2java's properties need to refer the axis docs --&gt;

&lt;!-- =================================================================== --&gt;

&lt;target name="wsdl2java"&gt;

    &lt;echo message="Generating java files from wsdl"/&gt;

    &lt;wsdl2java url="${dev.dir}/OpenBusinessService.wsdl"

               output="${dev.dir}"

               deployscope="session"

               serverSide="yes"

               skeletonDeploy="yes"

               noimports="no"

               verbose="yes"

               typeMappingVersion="1.1"

               testcase="yes"&gt;

            &lt;mapping namespace="http://134.96.71.13:8080/axis/OpenBusinessService.wsdl" package="com.int97.webserviceclient"/&gt;

        &lt;/wsdl2java&gt;

&lt;/target&gt;

   

&lt;!-- axis-java2wsdl is a taskdefing the public Axis taskdefs in the axis-tasks.properties--&gt;

&lt;target name="java2wsdl"&gt;

    &lt;echo message="Generating java files from wsdl"/&gt;

    &lt;!-- &lt;java2wsdl&gt; is equal with &lt;axis-java2wsdl&gt;--&gt;

    &lt;axis-java2wsdl output="${dev.dir}/OpenBusinessServiceTest.wsdl"

                  classname="com.int97.test.OpenBusinessService"

                  location="http://localhost:8080/axis/services/OpenBusinessService"

                  namespace="urn:OpenBusinessService"

                  style="RPC" &gt;

                  &lt;!-- classpath is neccesary, otherwise, &lt;java2wsdl&gt; won't find the class.

                  &lt;classpath refid="all.classpath" /&gt; --&gt;

                  &lt;classpath path="${dev.classes.dir}" /&gt;

    &lt;/axis-java2wsdl&gt;

&lt;/target&gt;

 

   

&lt;!-- Deprecated

&lt;target name="compile" depends="copy"&gt;

 

 &lt;javac srcdir="${axis.home}" destdir="${build.dest}" debug="${debug}" nowarn="${nowarn}" source="${source}" fork="${javac.fork}"&gt;

    &lt;classpath&gt;

        &lt;path refid="classpath"/&gt;

    &lt;/classpath&gt;

    &lt;include name="samples/addr/\*\*/\*.java"/&gt;

    &lt;exclude name="samples/addr/\*.java" /&gt;

    &lt;exclude name="samples/\*\*/\*SMTP\*.java" unless="smtp.present" /&gt;

    &lt;exclude name="\*\*/old/\*\*/\*.java" /&gt;

 &lt;/javac&gt;

 

    &lt;wsdl2java url="${axis.home}/samples/addr/AddressBook.wsdl"

               output="${build.dir}/work"

               deployscope="session"

               serverSide="yes"

               skeletonDeploy="yes"

               noimports="no"

               verbose="no"

               typeMappingVersion="1.1"

               testcase="no"&gt;

        &lt;mapping namespace="urn:AddressFetcher2" package="samples.addr"/&gt;

    &lt;/wsdl2java&gt;

 

    &lt;copy todir="${build.dir}/work/samples/addr" overwrite="yes"&gt;

      &lt;fileset dir="${axis.home}/samples/addr"&gt;

        &lt;include name="Main.java"/&gt;

        &lt;include name="DOMUtils.java"/&gt;

        &lt;include name="AddressBookSOAPBindingImpl.java"/&gt;

      &lt;/fileset&gt;

    &lt;/copy&gt;

 

       Compile the echo sample generated java files

    &lt;javac srcdir="${build.dir}/work" destdir="${build.dest}" debug="${debug}" nowarn="${nowarn}" source="${source}" fork="${javac.fork}"&gt;

      &lt;classpath refid="classpath" /&gt;

      &lt;include name="samples/addr/\*\*.java" /&gt;

    &lt;/javac&gt;

 

&lt;/target&gt;

--&gt;

   

&lt;!-- Use this file to undeploy some handlers/chains and services    --&gt;

&lt;!-- Two ways to do this:                                           --&gt;

&lt;!--   java org.apache.axis.client.AdminClient undeploy.wsdd        --&gt;

&lt;!--      after the axis server is running                          --&gt;

&lt;!-- or                                                             --&gt;

&lt;!--   java org.apache.axis.utils.Admin client|server undeploy.wsdd --&gt;

&lt;!--      from the same directory that the Axis engine runs         --&gt;

 

&lt;!-- ???AdminService is setted in the server-config.wsdd, it's class is

     org.apache.axis.utils.Admin

     

     servletpath the path to the AxisAdmin servlet

     url full url to the admin endpoint  

 --&gt;

&lt;target name="deploy"&gt;

    &lt;axis-admin port="8080" hostname="localhost" failonerror="true"

       servletpath="${app.name}/services/AdminService" debug="true"

       xmlfile="${basedir}/deploy.wsdd" /&gt;

&lt;/target&gt;

   

&lt;target name="undeploy"&gt;

    &lt;axis-admin port="8080" hostname="localhost" failonerror="true"

       servletpath="${app.name}/services/AdminService" debug="true"

       xmlfile="${basedir}/undeploy.wsdd" /&gt;

&lt;/target&gt;

   

&lt;!--&lt;target name="run"/&gt; --&gt;

 

&lt;!-- &lt;target name="undeploy"/&gt; --&gt;

 

&lt;!-- ============================================

          Reference Resource

    ============================================

    target name="j2w-nicethingsbean"&gt;

        &lt;axis-java2wsdl   classname="samples.ejb.NiceThingsBean"

           methods="sayHello,findNiceThingsFor,updateNiceThingsFor"

                        output="nicethings.wsdl"

                        location="http://localhost:8080/axis/services/NiceThingsBean"

                        namespace="http://localhost:8080/axis/services/NiceThingsBean"

                        namespaceImpl=

                            "http://localhost:8080/axis/services/NiceThingsBean"&gt;

            &lt;complextype classname="samples.ejb.NiceThings"

                         namespace="urn:NiceThingsBean"/&gt;

&lt; You can also pass in another serializer/deserializer if you don't want to use the default

        BeanSerializerFactory for a particular complextype

                 serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

                 deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory" &gt;

        &lt;/axis-java2wsdl&gt; 

    &lt;/target&gt;  

--&gt;

&lt;/project&gt;