Web Services教程

术语简介:

 

1.Web Services:Web Services是由企业发布的完成其特定商务需求的在线应用服务,其他公司或应用软件能够通过Internet来访问并使用这项在线服务。Web Service是一个应用组件,它逻辑性的为其他应用程序提供数据与服务.各应用程序通过网络协议和规定的一些标准数据格式(HttpXMLSoap)来访问Web Service,通过Web Service内部执行得到所需结果.Web Service可以执行从简单的请求到复杂商务处理的任何功能。一旦部署以后,其他Web Service应用程序可以发现并调用它部署的服务。

2.WSDL: Web Services Description Language的缩写,是一个用来描述Web服务和说明如何与Web服务通信的XML语言。WSDLWeb Service的描述语言,用于描述Web Service的服务,接口绑定等,为用户提供详细的接口说明书

3.AXISAxis本质上就是一个SOAP引擎,提供创建服务器端、客户端和网关SOAP操作的基本框架,支持WSDL,提供转化WSDLJava类的工具

 

大纲:

一,AXIS1.X发布webservice

二,AXIS2发布webservice

三,WSDL文件

四,wsdl2Java ,java2Wsdl工具

五,spring,webwork,axis2等发布WEBSERVICE

 

 

 

 

Axis目前有两种版本,Axis1.x Axis2,它们发布webservice的方式有些差别,由于目前我们平台开发主要用的比较多的是axis2,所以Axis1.x就简单了解下它是如何发布WebService的。

 

(一)AXIS1.X发布webservice

 

1.第一步开始安装axis1.X.

我们可以从axis的官方网站上下载(http://ws.apache.org/axis/).解压缩axis-bin-1_4.zipDaxiswebapps文件夹中包含了一个axis web application你可以直接把他拷贝到tomcat/webapps中,然后在这个axis应用上发布你的webservice,发布成功后就可以调用了。重新启动tomcat.访问http://localhost:8080/axis。这时就会出现axis的欢迎画面.进入Validation链接以检查axis所使用的jar包是否全都存在。如果不存在就会显示以下画面:

我们可以根据链接下载axis缺少的jar文件,下载之后copytomcat\webapps\myaxis\WEB-INF\lib下即可。一般情况下还会有一些warning消息,里面列出的选项不是必须存在的jar包。当必须的jar文件全部安装完毕,则会出现以下画面。

2.第二步:测试axis

在测试axis之前我们需要一些准备工作。

设置axis环境变量(设置完后,应重启控制台,才会生效)

AXIS_HOME D:\axis

AXIS_LIB%AXIS_HOME%\lib

AXISCLASSPATH:%AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discovery.jar;%AXIS_LIB%\commons-logging.jar;%AXIS_LIB%\jaxrpc.jar;%AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j-1.2.8.jar;%AXIS_LIB%\xml-apis.jar;%AXIS_LIB%\xercesImpl.jar

(同时将AXISCLASSPATH添加到classpath中)

注意路径是根据自己部署情况而定,上面的只是参考。

 

A.通过jws方式发布

我们通过JWS (Java Web Service)文件的方式来发布一个webservice。编写一个简单的java类,SimpleService.java,将其改名为SimpleService.jws然后copytomcatwebapps/axis/下。重启tomcat,发布这个webservice。这个webservice提供了一个简单的sayHello功能。

Webservice code:

public class SimpleService{

public String sayHello(String name) {

        return"hello: " + name;

    }

}

发布完后,可以打开http://localhost:8080/axis/SimpleService.jws查看是否服务发布成功

点击“Click to see the WSDL”即可看到该服务的WSDL文件

 

下面可以编写客户端代码调用该服务:

Client code:

import java.net.MalformedURLException;

import java.net.URL;

import java.rmi.RemoteException;

import javax.xml.namespace.QName;

import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

 

public class Client {

       public static void main(String[] args) throws ServiceException, MalformedURLException, RemoteException {

 String textToSend;

              if ((args == null) || (args.length < 1)) {

                textToSend = "<nothing>";

            } else {

                textToSend = args[0];

            }

              Service service = new Service();

              Call call = (Call) service.createCall();

              String path = "http://localhost:8080/axis/SimpleService.jws";

              call.setTargetEndpointAddress(new URL(path));

              call.setOperationName(new QName(path, "sayHello"));

              Object obj = call.invoke(new Object[] { textToSend });

              System.out.println(obj.toString());

       }

}

下面我们来进行调用。首先进入客户端源代码所在位置

然后输入

Javac Client.java

java Client Jim

这时如果结果为Hello:Jim则说明axis安装成功!

如果失败了请检查classpath设置,是否将所有用到的jar文件加入classpath中。

 

B.通过wsdd文件方式发布WEBSERVICE

jws这种发布方式非常的敏捷。不过在这简单背后却是以牺牲灵活性为代价的。假如你现在手里只有.class 或者一个jar包,jws就不再能满足你的需求了,最要命的就是即时发布不支持带包的类,所以下面介绍通过wsdd文件的方式发布Webservice.

 

     现在我们来通过一个wsdd文件来对wsdd有个初步的认识。

xml 代码

<deployment xmlns="http://xml.apache.org/axis/wsdd/" 

            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> 

            <service name="calculator" provider="java:RPC"> 

                   <parameter name="className" value="com.ws.service.Calculator"/> 

                   <parameter name="allowedMethods" value="*"/> 

            </service> 

</deployment>

最外面的元素告诉我们这是一个wsdd发布项,并且定义了java的命名空间,service元素定义了我们的service,java:RPC定义了axisproviderparameter name定义了webservice类名及所在包的位置。allowedMethods value等于*,表示Calculator的所有方法都可以被调用。

编写服务类Calculator.java

package com.ws.service;

public class Calculator {

       public Calculator() {

       }

       public String calculator(String str) {

              return "Hello " + str;

       }

       public int add(int a, int b) {

              return a + b;

       }

}

 

   了解了wsdd文件,我们来认识一个非常有用的工具AdminClient.正式通过它我们才能通过wsdd文件发布我们的应用。它的全路径是 org.apache.axis.client.AdminClient,在axis.jar包中。之前已经将该jar添加到classpath中了,所以可以直接使用。

   我们首先进入webservice所在源文件的目录找到deploy.wsdd文件(通常将该文件放至axis\WEB-INF)。然后键入如下命令:

          java org.apache.axis.client.AdminClient deploy.wsdd

         (如果提示错误,请检查你是否将必须的jar包加入classpath

          如果成功则会显示:

<Admin>Done processing</Admin> 

打开浏览器“http://localhost:8080/axis/servlet/AxisServlet”,会发现

java.lang.ClassNotFoundException: com.ws.service.Calculator

所以还应该将服务类编译,将.class文件放至“tomcat\webapps\axis\WEB-INF\classes\com\ws\service”,重启tomcat,再次打开浏览器,就会发现服务已经起来了

 

客户端测试类

package com.ws.service;

 

import java.net.MalformedURLException;

import java.net.URL;

import java.rmi.RemoteException;

import javax.xml.namespace.QName;

import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

public class CalculatorClient {

       public static void main(String[] args) throws ServiceException,

                     MalformedURLException, RemoteException {

 

              String targetEendPoint = "http://localhost:8080/axis/services/calculator";

              Service service = new Service();

              Call call = (Call) service.createCall();

              call.setTargetEndpointAddress(new URL(targetEendPoint));

              call.setOperationName(new QName(targetEendPoint, "calculator"));

              String result = (String) call.invoke(new Object[] { "Robert" });

              System.out.println(result);

 

              call.setOperationName(new QName(targetEendPoint, "add"));

              Integer res = (Integer) call.invoke(new Object[] { new Integer(1),

                            new Integer(2) });

              System.out.println("The result is: " + res);

       }

}     

 

    下面来解释AdminClient 所做的工作。AdminClient 首先会在axis.jar所在应用下的WEB-INF文件夹下创建一个webservice配置文件server-config.wsdd,并且根据wsdd文件的配置将我们的webservice加入到这个配置文件中。如果server-config.wsdd已经存在则不会创建,会修改这个文件将新的service 配置到server-config.wsdd文件中。

我们来访问一下看看:(进入目录“tomcat\webapps\axis\WEB-INF\classes)

Javac com.ws.service.CalculatorClient .java

Java com.ws.service.CalculatorClient


Hello Robert

The result is: 3  

返回正确,部署成功!

   如果你要卸载一个webservice也很简单!我们首先定义一个undeploy.wsdd

<undeployment xmlns="http://xml.apache.org/axis/wsdd/"> 

<service name="calculator"/> 

</undeployment> 

进入webservice所在源文件的目录找到undeploy.wsdd文件(通常将该文件放至axis\WEB-INF)。然后键入如下命令:

   java org.apache.axis.client.AdminClient undeploy.wsdd

(如果提示错误,请检查你是否将必须的jar包加入classpath

       
  
如果成功则会显示:

<Admin>Done processing</Admin> 

server-config.wsdd已经删除了原来service的定义

打开浏览器访问“http://localhost:8080/axis/services”,calculator服务已消失

 

附:webservice 服务发布成功之后,客户端一般有两种方式进行调用,第一种:通过JAX-RPC方式JAX-RPC是啥,详情请“百度”了解),上面用到的客户端调用就是属于该方式;另一种是通过WSDL2Java工具,通过wsdl文件产生客户端stub,然后通过该stub就可以直接调用服务器,就不需要像第一种写的那么繁琐,至于wsdl文件和WSDL2Java是什么,我们后面再介绍;

 

 

 

(二)AXIS2发布webservice

 

Axis2axis经过重新设计后的版本,操作相比axis1.x版本方便

1.下载axis2

http://axis.apache.org/axis2/java/core/download.cgi   下载war 版本即可

2.安装

解压axis2-1.5.4-war.zip ,将axis2.war 放至tomcat/webapps 下,启动tomcat

打开浏览器,访问:http://localhost:8080/axis2/

安装成功与否,确认方式同axis1.x

3.发布webservice ,可参考开发文档

http://axis.apache.org/axis2/java/core/docs/quickstartguide.html

 

Axis2 不支持jws即时发布方式,同时也摈弃了笨重的wsdd发布的方式AXIS2只要创建一个服务文档(.aar)文件,将其部署到tomcat下即可

 

A.通过无配置的方式发布ws

新建服务类(该pojo类同样不能有package关键字声明包)

SimpleService2.java

publicclass SimpleService2 {

    public String getGreeting(String name) {

        return"hello," + name;

    }

    publicint getPrice() {

        returnnew java.util.Random().nextInt(1000);

    }

}

 

编译SimpleService2类后,将SimpleService2.class文件放到<Tomcat安装目录>\webapps\axis2\WEB-INF\pojo目录中(如果没有pojo目录,则建立该目录)。现在我们已经成功将SimpleService2类发布成了WebService。在浏览器地址栏中输入如下的URL

http://localhost:8080/axis2/services/listServices ,可看到该服务。

 在浏览器地址栏中输入如下的两个URL来分别测试getGreetinggetPrice方法:

http://localhost:8080/axis2/services/SimpleService2/getGreeting?name=bill

http://localhost:8080/axis2/services/SimpleService2/getPrice

 

客户端代码调用:

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;

import org.apache.axis2.addressing.EndpointReference;

import org.apache.axis2.client.Options;

import org.apache.axis2.rpc.client.RPCServiceClient;

 

public class RPCClient {

       @SuppressWarnings("unchecked")

       public static void main(String[] args) throws AxisFault {

              RPCServiceClient serviceClient = new RPCServiceClient();

              Options options = serviceClient.getOptions();

              EndpointReference taReference = new EndpointReference("http://localhost:8080/axis2/services/SimpleService2");

              options.setTo(taReference);

              Object[] opAddEntryArgs = new Object[] { "超人" };

              Class[] classes = new Class[] { String.class };

              QName opAddEntry = new QName("http://ws.apache.org/axis2", "getGreeting");

              System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0]);

              classes = new Class[] { int.class };

              opAddEntry = new QName("http://ws.apache.org/axis2", "getPrice");

              System.out.println(serviceClient.invokeBlocking(opAddEntry, new Object[] {}, classes)[0]);

       }

}

 

在编写客户端代码时应注意如下几点:

1. 客户端代码需要引用很多Axis2jar包,可通过eclipse新建项目方式,将用到的jar包全部导入,如果要通过命令行,那么得将如此多的jar文件添加到classpath环境变量中

  2. 在本例中使用了RPCServiceClient类的invokeBlocking方法调用了WebService中的方法。invokeBlocking方法有三个参数,其中第一个参数的类型是QName对象,表示要调用的方法名;第二个参数表示要调用的WebService方法的参数值,参数类型为Object[];第三个参数表示WebService方法的返回值类型的Class对象,参数类型为Class[]。当方法没有参数时,invokeBlocking方法的第二个参数值不能是null,而要使用new Object[]{}

    3. 如果被调用的WebService方法没有返回值,应使用RPCServiceClient类的invokeRobust方法,该方法只有两个参数,它们的含义与invokeBlocking方法的前两个参数的含义相同。

4. 在创建QName对象时,QName类的构造方法的第一个参数表示WSDL文件的命名空间名,也就是<wsdl:definitions>元素的targetNamespace属性值,可通过浏览器访问该服务的wsdl文件,获取该值

 

B.通过services.xml文件配置的方式发布ws

Axis2实现Web Service,虽然可以将POJO类放在axis2\WEB-INF\pojo目录中直接发布成Web Service,这样做不需要进行任何配置,但这些POJO类不能在任何包中。这似乎有些不方便,为此,Axis2也允许将带包的POJO类发布成Web Service

   编写服务类MyService.java

package com.ws.service;

public class MyService {

       public String getGreeting(String name) {

              return "hello," + name;

       }

       public int getPrice() {

              return new java.util.Random().nextInt(1000);

       }

}

这个类同样有两个方法,这两个方法都需要发布成Web Service方法。这种方式和直接放在pojo目录中的POJO类不同。要想将MyService类发布成Web Service,需要一个services.xml文件,这个文件需要放在META-INF目录中,该文件的内容如下:

 

 

services.xml

 

<service name="myService">

       <description>Web?Service例子</description>

       <parameter name="ServiceClass">com.ws.service.MyService</parameter>

       <messageReceivers>

              <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>

              <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>

       </messageReceivers>

</service>

其中<service>元素用于发布Web Service,一个<service>元素只能发布一个WebService类,name属性表示WebService名,如下面的URL可以获得这个WebServiceWSDL内容:

http://localhost:8080/axis2/services/myService?wsdl 

其中name属性名就是上面URL"?""/"之间的部分。

<description>元素表示当前Web Service的描述,<parameter>元素用于设置WebService的参数,在这里用于设置WebService对应的类名。在这里最值得注意的是<messageReceivers>元素,该元素用于设置处理WebService方法的处理器。例如,getGreeting方法有一个返回值,因此,需要使用可处理输入输出的RPCMessageReceiver类,而update方法没有返回值,因此,需要使用只能处理输入的RPCInOnlyMessageReceiver类。

使用这种方式发布WebService,必须打包成.aar文件,..aar文件实际上就是改变了扩展名的.jar文件。在现在建立了两个文件:MyService.javaservices.xml。将MyService.java编译,生成MyService.classservices.xmlMyService.class文件的位置如下:

 

D:\ws\com\ws\service\MyService.class

D:\ws\META-INF\services.xml

 

   windows控制台中进入ws目录,并输入如下的命令生成.aar文件(实际上,.jar文件也可以发布webservice,但axis2官方文档中建议使用.aar文件发布webservice):

jar cvf ws.aar . (注意后面有个“.”)
    最后将ws.aar文件复制到<Tomcat安装目录>\webapps\axis2\WEB-INF\services目录中,启动Tomcat后,就可以调用这个WebService

(三) wsdl2java工具java2wsdl工具)

   也许有很多人会说“有没有搞错啊,只调用两个WebService方法用要写这么多代码(通过JAX-RPC方式),太麻烦了”。

    不过幸好Axis2提供了一个wsdl2java.bat命令可以根据WSDL文件自动产生调用WebService的代码。wsdl2java.bat命令可以在<Axis2安装目录>"bin目录中找到。在使用wsdl2java.bat命令之前需要设置AXIS2_HOME环境变量,该变量值是<Axis2安装目录>

Windows控制台输出如下的命令行来生成调用WebService的代码:进入axis2/bin目录,执行

wsdl2java -uri http://localhost:8080/axis2/services/ myService?wsdl -p client -s -o stub

其中-uri参数指定了wsdl文件的路径,可以是本地路径,也可以是网络路径。-p参数指定了生成的Java类的包名,-o参数指定了生成的一系列文件保存的根目录。在执行完上面的命令后,读者就会发现在当前目录下多了个stub目录,在. Stub.src.client目录可以找到一个MyServiceStub.java文件,该文件负责调用WebService,可以在程序中直接使用这个类,代码如下

 

package client;

public class StubClient {

       public static void main(String[] args) throws Exception {

              MyServiceStub stub = new MyServiceStub();

              MyServiceStub.GetGreeting gg = new MyServiceStub.GetGreeting();

              gg.setArgs0("比尔");

              System.out.println(stub.getGreeting(gg).get_return());

              System.out.println(stub.getPrice().get_return());

       }

}

 

执行结果:

hello,比尔

207(随机数字)

上面的代码大大简化了调用WebService的步骤,并使代码更加简洁。但要注意的是,wsdl2java.bat命令生成的Stub类将WebService方法的参数都封装在了相应的类中,类名为方法名,例如,getGreeting方法的参数都封装在了GetGreeting类中,要想调用getGreeting方法,必须先创建GetGreeting类的对象实例。

 

(四)WSDL文件

Web Services Description Language的缩写,是一个用来描述Web服务和说明如何与Web服务通信的XML语言。

WSDLWeb Service的描述语言,用于描述Web Service的服务,接口绑定等,为用户提供详细的接口说明书,通常有以下几个元素组成。

 

<portType> web service 执行的操作

<message> web service 使用的消息

<types> web service 使用的数据类型

<binding> web service 使用的通信协议

 

例子:(wsdl教程可以参考“http://www.w3school.com.cn/wsdl/)

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions targetNamespace="http://goodhope.com/robotservice" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://goodhope.com/robotservice" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:types="http://goodhope.com/robotservice/messages/types" xmlns:messages="http://goodhope.com/robotservice/messages">

  <wsdl:types>

    <xsd:schema elementFormDefault="qualified" targetNamespace="http://goodhope.com/robotservice/messages">

                     <xsd:import namespace="http://goodhope.com/robotservice/messages/types"/>

                     <xsd:element name="ResponseMessage">

                            <xsd:complexType>

                                   <xsd:sequence>

                                          <xsd:element name="code" nillable="false" type="xsd:int"/>

                                          <xsd:element name="message" nillable="true" type="xsd:string"/>

                                   </xsd:sequence>

                            </xsd:complexType>

                     </xsd:element>

 

                     <xsd:element name="RequestMessage">

                            <xsd:complexType>

                                   <xsd:sequence>

                                          <xsd:element name="taskId" nillable="false" type="xsd:long"/>

                                          <xsd:element name="amount" nillable="true" type="xsd:long"/>

                                          <xsd:element name="roleName" nillable="false" type="xsd:string"/>

                                          <xsd:element name="deadLine" nillable="false" type="xsd:long"/>

                                          <xsd:element name="tradeType" nillable="false" type="xsd:string"/>

                                   </xsd:sequence>

                            </xsd:complexType>

                     </xsd:element>

              </xsd:schema>

  </wsdl:types>

  <wsdl:message name="request">        -à<message>定义一个操作的数据元素,可以理解为输入或输出参数

    <wsdl:part name="requestMessage" element="messages:RequestMessage">

    </wsdl:part>

  </wsdl:message>

  <wsdl:message name="response">

    <wsdl:part name="responseMessage" element="messages:ResponseMessage">

    </wsdl:part>

  </wsdl:message>

  <wsdl:portType name="RobotServicePortType">         --à<portType>wsdl端口,可以理解为一个服务类

    <wsdl:operation name="assignTask">

      <wsdl:input name="request" message="tns:request">

    </wsdl:input>

      <wsdl:output name="response" message="tns:response">

    </wsdl:output>

    </wsdl:operation>

  </wsdl:portType>

  <wsdl:binding name="robotServiceSoapBinding" type="tns:RobotServicePortType">  <binding> 元素为每个端口定义消息格式和协议细节

    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

    <wsdl:operation name="assignTask">         <operation>可以理解为类中的一个方法

      <soap:operation soapAction="http://goodhope.com/robotservice/assignTask"/>

      <wsdl:input name="request">             

        <soap:body use="literal"/>

      </wsdl:input>

      <wsdl:output name="response">

        <soap:body use="literal"/>

      </wsdl:output>

    </wsdl:operation>

  </wsdl:binding>

  <wsdl:service name="RobotService">

    <wsdl:port name="RobotServicePort" binding="tns:robotServiceSoapBinding">

      <soap:address location="http://localhost:23080/axis2/services/RobotService"/>

    </wsdl:port>

  </wsdl:service>

</wsdl:definitions>

 

 

(五)集成ant,spring,webwork,axis2等发布WEBSERVICE

 实际在企业开发过程中,不可能都只是这么简单的通过一个类发布webservice服务,有些服务需要传输对象、文件、图片等,通常都会与其他框架、工具整合,比如SSHant

 

一般开发步骤:

1.编写wsdl文件,通过wsdl2java 生成服务端代码和客户端代码,然后在服务端代码里面添加自己的具体实现功能,或者直接编写服务类,然后通过java2wsdl工具,创建wsdl文件

2.编写services.xml文件,声明要发布的服务及服务类等

3打包.aaraxis2/WEB-INF/servicesaar内容,请参考“通过services.xml文件配置的方式发布ws”)

4.将与该服务关联的class文件以及class文件用到的图片,文本文件等打包(也可以将它们拷贝至axis2/WEB-INF/classes文件夹)、jar包等拷贝到axis2/WEB-INF/lib下(注意.classpackage路径也要匹配)

5.将与该服务关联的xmlproperties、图片、文本文件等拷贝到axis2/WEB-INF/classes目录下

6.启动tomcat,确认服务起来后,即可编写客户端代码进行服务调用(可通过wsdl2java工具生成客户端代码)

 

下面提供一个实际开发中的简洁版本的例子,大家可以了解下:

 

<project name="wsapp" basedir="." default="force.deploy">

       <property name="build.dir" value="${basedir}/build" />

       <property name="build.lib.dir" value="${basedir}/build/lib" />

       <property name="lib.dir" value="${basedir}/lib" />

       <property name="classes.dir" value="${build.dir}/classes" />

       <property name="build.recources" value="${build.dir}/recources" />

       <property name="test.classes.dir" value="${build.dir}/classes/test" />

       <property name="src.classes.dir" value="${build.dir}/classes/src" />

       <property name="config.dir" location="${basedir}/config" />

       <property name="resources" location="${basedir}/resources" />

       <property name="src.dir" value="${basedir}/src" />

       <property name="test.src.dir" value="${basedir}/test" />

       <property name="autogen.dir" value="${basedir}/autogen" />

       <property name="robot.wsdl.dir" value="${basedir}/wsdl/robot.wsdl" />

       <!--tomcat-->

       <property name="tomcat.home" value="${basedir}/../tomcat-moyuRobot" />

       <property name="tomcat.manager.url" value="http://localhost:23080/manager" />

       <property name="tomcat.username" value="admin" />

       <property name="tomcat.password" value="" />

<path id="axis2.class.path">

              <fileset dir="${lib.dir}/axis2">

                     <include name="*.jar" />

              </fileset>

              <fileset dir="${lib.dir}/common" includes="*.jar" />

       </path>

       <target name="-clean">

              <delete dir="${build.dir}" failοnerrοr="false" />

              <delete dir="${autogen.dir}" failοnerrοr="false" />

              <delete dir="${tomcat.home}/webapps/axis2/WEB-INF/classes/" failοnerrοr="false" />

              <delete file="${tomcat.home}/webapps/axis2/WEB-INF/lib/myRobot.jar" failοnerrοr="false" />

              <delete file="${tomcat.home}/webapps/axis2/WEB-INF/services/myRobotServer.aar" failοnerrοr="false" />

              <delete dir="${tomcat.home}/temp" failοnerrοr="false" />

              <delete dir="${tomcat.home}/work" failοnerrοr="false" />

       </target>

       <target name="-init">

              <mkdir dir="${build.dir}" />

              <mkdir dir="${autogen.dir}" />

              <mkdir dir="${classes.dir}" />

              <mkdir dir="${test.classes.dir}" />

              <mkdir dir="${src.classes.dir}" />

              <mkdir dir="${build.recources}" />

              <mkdir dir="${build.lib.dir}" />

              <mkdir dir="${tomcat.home}/webapps/axis2/WEB-INF/classes/" />

       </target>

       <target name="-generate.robot.skeleton">

              <delete dir="${autogen.dir}" failοnerrοr="false" />

              <mkdir dir="${autogen.dir}" />

              <java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true" classpathref="axis2.class.path">

                     <arg line="-uri ${robot.wsdl.dir}" />

                     <arg line="-a" />

                     <arg line="-ap" />

                     <arg line="-ss" />

                     <arg line="-ssi" />

                     <arg line="-sd" />

                     <arg line="-S ." />

                     <arg line="--noBuildXML" />

                     <arg line="-R ../resources" />

                     <arg line="-l java" />

                     <arg line="-o ${autogen.dir}" />

              </java>

       </target>

       <target name="-compile">

              <javac destdir="${src.classes.dir}" source="1.5" target="1.5" debug="true" encoding="UTF-8">

                     <src path="${src.dir}" />

                     <src path="${autogen.dir}" />

                     <classpath refid="classpath" />

              </javac>

              <copy todir="${src.classes.dir}" overwrite="yes">

                     <fileset dir="${src.dir}">

                            <include name="**/*.bmp" />

                            <include name="**/*.jpg" />

                            <include name="**/*.JPG" />

                            <include name="**/*.txt" />

                     </fileset>

              </copy>

              <javac destdir="${test.classes.dir}" source="1.5" target="1.5" debug="true" encoding="UTF-8">

                     <src path="${test.src.dir}" />

                     <classpath refid="classpath" />

              </javac>

              <copy todir="${test.classes.dir}" overwrite="yes">

                     <fileset dir="${config.dir}/app">

                            <include name="*" />

                     </fileset>

              </copy>

              <!-- copy image and xml data files for only test classes -->

              <copy todir="${test.classes.dir}">

                     <fileset dir="${test.src.dir}">

                            <include name="**/*.bmp" />

                            <include name="**/*.jpg" />

                            <include name="**/*.JPG" />

                            <include name="**/*.ini" />

                     </fileset>

              </copy>

       </target>

       <target name="-jar.jars">

              <jar jarfile="${build.lib.dir}/myRobot.jar">

                     <fileset dir="${src.classes.dir}" />

              </jar>

              <jar destfile="${build.lib.dir}/myRobotServer.aar">

                     <metainf dir="${basedir}/resources">

                            <include name="*.xml" />

                            <include name="*.wsdl" />

                     </metainf>

              </jar>

              <copy todir="${tomcat.home}/webapps/axis2/WEB-INF/classes" overwrite="yes">

                     <fileset dir="${config.dir}/app">

                            <include name="*.xml" />

                            <include name="gameServiceSSL.properties" />

                            <include name="myRobot.ks" />

                            <include name="myRobot.ts" />

                     </fileset>

              </copy>

       </target>

       <target name="-deploy.jar.and.aar">

              <copy todir="${tomcat.home}/webapps/axis2/WEB-INF" overwrite="yes" file="${config.dir}/WEB-INF/web.xml" />

              <copy file="${build.lib.dir}/myRobot.jar" toDir="${tomcat.home}/webapps/axis2/WEB-INF/lib" overwrite="yes" />

              <copy file="${lib.dir}/comm.jar" toDir="${tomcat.home}/webapps/axis2/WEB-INF/lib" overwrite="yes" />

              <copy file="${build.lib.dir}/myRobotServer.aar" toDir="${tomcat.home}/webapps/axis2/WEB-INF/services" overwrite="yes" />

       </target>

       <target name="--deploy" depends="stop.tomcat, -clean, -init, -generate.robot.skeleton, -compile,  -jar.jars, -deploy.jar.and.aar, start.tomcat" />

       <target name="force.deploy" depends="--deploy" description="force.deploy" />

       <target name="stop.tomcat" description="stop.tomcat">

              <ant antfile="build.xml" dir="${tomcat.home}" target="stop.tomcat" inheritAll="false" />

       </target>

       <target name="start.tomcat" description="start.tomcat">

              <ant antfile="build.xml" dir="${tomcat.home}" target="start.tomcat" inheritAll="false" />

       </target>

</project>

 

 

(六)一些常用的webservice服务

 http://hi.baidu.com/sushangzhou/blog/item/e5d315ca8126d016be09e6e0.html

 http://www.webxml.com.cn/zh_cn/index.aspx

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值