eclipse开发webservice实例及问题解决

来源:互联网 发布:淘宝客怎么建个工作室 编辑:程序博客网 时间:2024/06/07 02:17

1.开发环境及准备工作

系统:windows7 

jdk:1.8

eclipse :4.6.3(一般版本通用的)

下载Apache Axis2 :http://mirror.bit.edu.cn/apache/axis/axis2/java/core/1.7.6/axis2-1.7.6-bin.zip

  解压缩得到的目录,目录内的文件结构如下:

*****配置tomcat 服务器:将下载的tomcat服务器配置上去(这不是重点,简单说)

2.开发前配置

在Eclipse的菜单栏中,Window --> Preferences --> Web Service --> Axis2 Perferences,在Axis2 runtime location中选择Axis2解压缩包的位置,设置好后,点"OK"即行。



3.开发Web Service

我们做一个计算器的websevice

1.新建Java工程及CalculateService类目录如下:


CalculateService类中的代码如下(包含加减乘除的计算):

package com.mjy.test;public class CalculateService {    //加法      public float plus(float x, float y) {        return x + y;    }    //减法      public float minus(float x, float y) {        return x - y;    }    //乘法      public float multiply(float x, float y) {        return x * y;    }    //除法      public float divide(float x, float y) {        if (y != 0) {            return x / y;        } else            return -1;    }}

2.在项目名称上右键new --> other,找到"Web Services"下面的"Web Service";

选择刚刚创建的类,并配置如下


一路点击next:要等一会儿,喝口水的功夫,,,。

点start server:没喝够?再来一口

等启完后,点击"next -- > next",一切默认即行,最后,点击完成。最后,出现如下界面:(Web Service Explorer),我们在这里便可测试我们的Web服务。


下面四个就是你写的计算器的功能了,自己试试