参考:http://www.blogjava.net/rongxh7/archive/2009/05/21/271982.html
Apache Axis2是第三代的Web services引擎。
一、开发前准备:
1、安装Eclipse-jee;
2、下载Axis2的最新版本Axis2 1.4.1 Release,网址
http://ws.apache.org/axis2/download/1_4_1/download.cgi ,选择Standard Binary Distribution
的.zip包即"axis2-1.4.1-bin.zip"这个文件,解压缩得到的目录名axis2-1.4.1。
二、开发前配置:
在Eclipse的菜单栏中,Window --> Preferences --> Web Service --> Axis2 Perferences,在Axis2 runtime location中选择Axis2解压缩包的位置,设置好后,点"OK"即行。
三、开发Web Service:
1、新建一个Java Project,命名为"WS_01";
2、新建一个class,命名为"CalculateService",实现web 服务;
3、在"WS_01"项目上new --> other,找到"Web Services"下面的"Web Service";
4、next,在出现的Web Services对象框,在Service implementation中点击"Browse",进入Browse Classes对象框,查找到我们刚才写的写的CalculateService类。点击"ok",则回到Web Service话框。
此处,我遇到的问题是:configuration里没有server。我的Eclipse中安装了tomcat插件tomcatPluginV321,以为不需要配置tomcat了。
实际上,tomcat插件只是可以让eclipse和tomcat协同工作的小程序。没有它,就无法在eclipse里操作tomcat,包括启动,自动部署一类。如果不安装插件,只要有eclipse和tomcat也可以开发。只是需要手动启动服务器、部署web应用。理解了这一点之后,只要在Eclipse中新建一个server即可,New-》other-》server。
5、在Web Service对话框中,将Web Service type中的滑块,调到"start service“的位置,将Client type中的滑块调到"Test client"的位置。
6、在Web Service type滑块图的右边有个"Configuration",点击它下面的选项,进入Service Deployment Configuration对象框,在这里选择相应的Server(我这里用Tomcat6.0)和Web Service runtime(选择Apache Axis2)。
7、到了Server startup对话框,有个按键"start server",点击它,则可启动Tomcat服务器了。
8、等启动完后,点击"next -- > next",一切默认即行,最后,点击完成。最后,出现界面:(Web Service Explorer),我们在这里便可测试我们的Web服务。
四、服务的发布
下载axis2-1.4.1-war.zip, 将 axis2.war 包拷贝到 tomcat 安装目录下的 webapps 目录中。 输入: http://localhost:8080/axis 2
将编译后的class文件复制到axis2/WEB-INF/pojo目录下(pojo目录是默认的,可以在axis2.xml中<axisconfig>修改),通过http://localhost:8080/axis2/services/listServices可以看到所有在axis2中发布的web service。
在浏览器中测试web service时,如果web service方法有参数,需要使用url的请求参数来指定该webservice方法参数的值,请求参数名与方法参数名要一致。