使用Jetty服务器和Axis2框架技术发布Webservice接口

时间:2023-01-18 22:20:46

1.所需要的工具

1.1 Ant工具 ,axis2-bin文件,axis2-war文件

这些工具和jar都可以从网上下载

2.下面我在eclipse中编写一个测试类,就是这么简单。

public class Add {
  public int add(int a,int b){
 return a+b;
  }
}

3.我们把axis2-war这个文件 解压之后,把axis2文件放入到jetty容器中的webapps目录下,D:\jetty-6.1.9\webapps

4.ant执行命令 

D:\caseone\test>ant generate.wsdl

D:\caseone\test>ant generate.service

执行成功之后 生成build文件

4.使用Jetty服务器和Axis2框架技术发布Webservice接口

.使用Jetty服务器和Axis2框架技术发布Webservice接口

5.把Add文件复制到

使用Jetty服务器和Axis2框架技术发布Webservice接口

6.service.xml文件

<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one
  ~ or more contributor license agreements. See the NOTICE file
  ~ distributed with this work for additional information
  ~ regarding copyright ownership. The ASF licenses this file
  ~ to you under the Apache License, Version 2.0 (the
  ~ "License"); you may not use this file except in compliance
  ~ with the License. You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an
  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~ KIND, either express or implied. See the License for the
  ~ specific language governing permissions and limitations
  ~ under the License.
  -->


<service name="Add" scope="application" targetNamespace="http://add/">
    <description>
        Add
    </description>
    <messageReceivers>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
                         class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
                         class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
    </messageReceivers>
    <schema schemaNamespace="http://Add/xsd"/>
    <parameter name="ServiceClass">Add</parameter>
</service>

7.bulid.xml文件

<project name="quickstart" basedir="." default="generate.service">
    <property environment="env"/>
    <property name="AXIS2_HOME" value="../.."/>
    <property name="build.dir" value="build"/>
    <path id="axis2.classpath">
        <fileset dir="${AXIS2_HOME}/lib">
            <include name="*.jar"/>
        </fileset>
    </path>

    <target name="compile.service">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.dir}/classes"/>

        <!--First let's compile the classes-->
        <javac debug="on" 
               fork="true"
               destdir="${build.dir}/classes" 
               srcdir="${basedir}/src"
               classpathref="axis2.classpath">
        </javac>
    </target>

    <target name="generate.wsdl" depends="compile.service">
        <taskdef name="java2wsdl"
                 classname="org.apache.ws.java2wsdl.Java2WSDLTask"
                  classpathref="axis2.classpath"/>
        <java2wsdl className="Add"
                   outputLocation="${build.dir}"
                   targetNamespace="http://add/"
                   schemaTargetNamespace="http://add/xsd">
            <classpath>
                <pathelement path="${axis2.classpath}"/>
                <pathelement location="${build.dir}/classes"/>
            </classpath>
        </java2wsdl>
    </target>

    <target name="generate.service" depends="compile.service">
        <!--aar them up -->
        <copy toDir="${build.dir}/classes" failonerror="false">
            <fileset dir="${basedir}/resources">
                <include name="**/*.xml"/>
            </fileset>
        </copy>
        <jar destfile="${build.dir}/add.aar">
            <fileset excludes="**/Test.class" dir="${build.dir}/classes"/>
        </jar>
    </target>


    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>
</project>

8.最后启动jetty

使用Jetty服务器和Axis2框架技术发布Webservice接口

9.以上文字演示视频