首页 > 代码库 > 用Axis2实现Web Service(简单的axis实现)
用Axis2实现Web Service(简单的axis实现)
一.开发环境:Tomcat(下载地址:http://tomcat.apache.org/download-60.cgi)、MyEclipse(下载地址:http://www.myeclipseide.cn/),Axis2(下载地址:http://axis.apache.org/axis2/java/core/download.cgi)。
二.MyEclipse插件:axis2-eclipse-codegen-wizard.zip(下载地址:http://files.cnblogs.com/sky-of-chuanqingchen/axis2-eclipse-codegen-wizard.zip),axis2-eclipse-service-archiver-wizard.zip(下载地址:http://files.cnblogs.com/sky-of-chuanqingchen/axis2-eclipse-service-archiver-wizard.zip)。
1.安装MyEclipse插件:将上述两个插件解压,再将解压后的文件复制到MyEclipse安装路径下的dropins目录,最后重启MyEclipse。(注:如在使用axis2 code generator创建wsdl文件的时候报错,报错信息如下图,可按照第三步的流程操作)。
2.检查是否成功安装MyEclipse插件,打开MyEclipse的File->New->Other,插件安装成功后如下图。
3.对axis2-eclipse-codegen-wizard.zip解压出来的文件做如下修改。
a.首先,修改plugin.xml文件,更改为如下代码。
1 <?xml version="1.0" encoding="UTF-8"?> 2 <?eclipse version="3.0"?> 3 4 <!-- 5 ~ Licensed to the Apache Software Foundation (ASF) under one 6 ~ or more contributor license agreements. See the NOTICE file 7 ~ distributed with this work for additional information 8 ~ regarding copyright ownership. The ASF licenses this file 9 ~ to you under the Apache License, Version 2.0 (the 10 ~ "License"); you may not use this file except in compliance 11 ~ with the License. You may obtain a copy of the License at 12 ~ 13 ~ http://www.apache.org/licenses/LICENSE-2.0 14 ~ 15 ~ Unless required by applicable law or agreed to in writing, 16 ~ software distributed under the License is distributed on an 17 ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 ~ KIND, either express or implied. See the License for the 19 ~ specific language governing permissions and limitations 20 ~ under the License. 21 --> 22 23 <plugin 24 id="Axis2_Codegen_Wizard" 25 name="Axis2 Codegen Wizard Plug-in" 26 version="1.3.0" 27 provider-name="Apache Software Foundation" 28 class="org.apache.axis2.tool.codegen.eclipse.plugin.CodegenWizardPlugin"> 29 30 <runtime> 31 <library name="Axis2CodegenWizard.jar"> 32 <export name="*"/> 33 </library> 34 <library name="lib/geronimo-activation_1.1_spec-1.0.1.jar"> 35 <export name="*"/> 36 </library> 37 <library name="lib/annogen-0.1.0.jar"> 38 <export name="*"/> 39 </library> 40 <library name="lib/ant-1.7.0.jar"> 41 <export name="*"/> 42 </library> 43 <library name="lib/axiom-api-1.2.7.jar"> 44 <export name="*"/> 45 </library> 46 <library name="lib/axiom-dom-1.2.7.jar"> 47 <export name="*"/> 48 </library> 49 <library name="lib/axiom-impl-1.2.7.jar"> 50 <export name="*"/> 51 </library> 52 <library name="lib/commons-logging-1.1.1.jar"> 53 <export name="*"/> 54 </library> 55 <library name="lib/axis2-1.4.1.jar"> 56 <export name="*"/> 57 </library> 58 <library name="lib/log4j-1.2.15.jar"> 59 <export name="*"/> 60 </library> 61 <library name="lib/neethi-2.0.4.jar"> 62 <export name="*"/> 63 </library> 64 <library name="lib/stax-api-1.0.1.jar"> 65 <export name="*"/> 66 </library> 67 <library name="lib/wsdl4j-1.6.2.jar"> 68 <export name="*"/> 69 </library> 70 <library name="lib/wstx-asl-3.2.4.jar"> 71 <export name="*"/> 72 </library> 73 <library name="lib/xmlbeans-2.3.0.jar"> 74 <export name="*"/> 75 </library> 76 <library name="lib/XmlSchema-1.4.2.jar"> 77 <export name="*"/> 78 </library> 79 <library name="lib/woden-1.0M8.jar"> 80 <export name="*"/> 81 </library> 82 <library name="lib/commons-httpclient-3.1.jar"> 83 <export name="*"/> 84 </library> 85 <library name="lib/commons-codec-1.3.jar"> 86 <export name="*"/> 87 </library> 88 <library name="lib/jibx-bind-1.1.5.jar"> 89 <export name="*"/> 90 </library> 91 <library name="lib/jibx-run-1.1.5.jar"> 92 <export name="*"/> 93 </library> 94 <library name="lib/geronimo-stax-api_1.0_spec-1.0.1.jar"> 95 <export name="*"/> 96 </library> 97 <library name="lib/backport-util-concurrent-3.1.jar"> 98 <export name="*"/> 99 </library>100 </runtime>101 102 <requires>103 <import plugin="org.eclipse.ui"/>104 <import plugin="org.eclipse.ui.ide"/>105 <import plugin="org.eclipse.core.runtime"/>106 <import plugin="org.eclipse.core.resources"/>107 <import plugin="org.apache.ant"/>108 </requires>109 110 <extension111 point="org.eclipse.ui.newWizards">112 <category113 name="Axis2 Wizards"114 id="Axis2_Wizards">115 </category>116 <wizard117 name="Axis2 Code Generator"118 icon="icons/icon.gif"119 category="Axis2_Wizards"120 class="org.apache.axis2.tool.codegen.eclipse.CodeGenWizard"121 id="org.apache.axis2.tool.codegen.eclipse.CodeGenWizard">122 </wizard>123 </extension>124 <extension point="org.eclipse.help.toc">125 <toc file="help_toc.xml" primary="true" />126 </extension>127 128 </plugin>
plugin.xml对比原始文件主要增加如下内容:
<library name="lib/geronimo-stax-api_1.0_spec-1.0.1.jar">
<export name="*"/>
</library>
<library name="lib/backport-util-concurrent-3.1.jar">
<export name="*"/>
</library>
b.其次,增加如下两个jar包(geronimo-stax-api_1.0_spec-1.0.1.jar、backport-util-concurrent-3.1.jar)到axis2-eclipse-codegen-wizard.zip所解压出来文件的lib目录下,(附jar包下载地址:http://files.cnblogs.com/sky-of-chuanqingchen/for_axis_code_generator.rar)。
三.开发一个简单的web service程序。
1.使用MyEclipse开发工具新建web service 项目,File->New->Web Service Project,如下图。
2.编写test.SimpleTest类,代码如下。
1 package test;2 3 public class SimpleTest {4 public String simpleMethod(String name) { 5 return name + "Say: this is a Simple test method ^-^"; 6 } 7 }
3.使用axis2 service archiver创建配置文件。
(注:output file location选择axis2所在项目目录下的\WebRoot\WEB-INF\services目录)
4.重启Tomcat服务器,打开url:http://localhost:8080/axis2/services/listServices,检查是否成功。
About MORE Axis2的相关资料,待续^-^
用Axis2实现Web Service(简单的axis实现)