WebService的开发模版(Axis21.5环境)今天在做apache-cxf-2.2.2整合Spring时候,出现了包版本与JDK1.5包冲突的问题,折腾了不少时间,还是没解决。于是改为Axis2开发,暂时绕过问题,完成任务要紧。Axis2已经升级到1.5了,下载地址:://apache.etoak.com/ws/axis2/1_5/axis2-1.5-war.zip两个包,bin是开发包,war是部署包,实际上,如果只用jar包,两个里面的jar都一样用。在IDEA环境下,Axis2的开发环境稍微麻烦些,毕竟没CXF或XFire方便。每次写build.xml脚本也挺麻烦的。这次写个项目模版,方便以后使用。环境:axis2-1.5jdk1.5idea-8.13apache-tomcat-6.0.20ant-1.6以上即可一、创建项目使用idea向导创建一个Java项目,项目结构如下图:testaxis2├─lib├─resources│└─META-INF└─src└─mytest二、导入axis2的包解压缩axis2-1.5-bin.zip到一个目录下,然后直接在idea中引入axis2的包即可。也可以讲axis2的包复制到lib下。三、创建服务axis2服务的创建过程就是写Java类,不要求有接口,有也不会错。这里创建一个最简单的Service,作为发布对象。packagemytest;/***测试Service**@authorleizhimin2009-8-415:46:39*/publicinterfaceMyService{StringdoSomething(Stringtaskname);}packagemytest;/***测试Service**@authorleizhimin2009-8-415:48:13*/publicclassMyServiceImplimplementsMyService{publicStringdoSomething(Stringtaskname){System.out.println(MyServiceImpliscallingdoSomethingwith+taskname+!);returntaskname+isfinished!;}}四、描述服务在项目的resources\META-INF文件夹下面,创建services.xml,内容如下:servicename=mywsscope=applicationtargetNamespace===org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver/messageReceivermep==org.apache.axis2.rpc.receivers.RPCMessageReceiver//messageReceiversschemaschemaNamespace==ServiceClassmytest.MyServiceImpl/parameter/service服务名:myws命名空间:服务实现类:mytest.MyServiceImpl五、编写构建脚本用Ant编写build.xml,放到项目根文件夹下。?xmlversion=1.0encoding=UTF-8?projectname=ccmwsbasedir=.default=generate.servicepropertyenvironment=env/propertyname=AXIS2_HOMEvalue=F:/axis2-1.5/propertyname=wsdl.urivalue=./build/myws.wsdl/propertyname=build.dirvalue=build/pathid=axis2.classpathfilesetdir=${AXIS2_HOME}/libincludename=*.jar//filesetfilesetdir=./libincludename=*.jar//fileset/pathtargetname=compile.servicemkdirdir=${build.dir}/mkdirdir=${build.dir}/classes/javacdebug=onfork=trueencoding=UTF-8destdir=${build.dir}/classessrcdir=${basedir}/srcextdirs=**/test/**classpathref=axis2.classpath/javac/targettargetname=generate.wsdldepends=compile.servicetaskdefname=java2wsdlclassname=org.apache.ws.java2wsdl.Java2WSDLTaskclasspathref=axis2.classpath/java2wsdlclassName=mytest.MyServiceImploutputLocation=${build.dir}targetNamespace===${axis2.classpath}/pathelementlocation=${build.dir}/classes//classpath/java2wsdl/targettargetname=generate.servicedepends=compile.servicecopytoDir=${build.dir}/classesfailonerror=falsefilesetdir=${basedir}/resourcesincludename=**/*.xml//fileset/copyjardestfile=${build.dir}/myws.aarfilesetexcludes=**/Test.classdir=${build.dir}/classes/filesetincludes=lib/*.jardir=${basedir}//jar/targettargetname=cleandeletedir=${build.dir}//target/project注意设定一些环境参数,Axis2的目录、发布服务的aar包名字,生成wsdl时候所用的服务实现类,以及命名空间等等。六、运行build脚本打包运行后:七、部署服务将下载的axis2-1.5-war.zip解开,得到一个axis2.war,将其解压缩到tomcat的默认的web发布目录webapp下面,比如,在我机器上会产生C:\apache-tomcat-6.0.20\webapps\axis2的目录,目录下面就是axis2.war里面的内容。然后,将生成的my.aar复制到C:\apache-tomcat-6.0.20\webapps\axis2\WEB-INF\services下面。八、启动tomcat,查看发布服务浏览axis2的服务点Services,查看所有的服务在点击服务连接,就可以查看wsdl了:经过这样的测试后,服务发布算成功了。