1. 准備:創建一個Maven Web App 項目
這里讓我們使用Maven 模板創建一個Web App 項目
1. New------> Maven Project
2. 使用默認配置,點擊Next
3. Catelog 選擇Internal ,Filter 輸入webappp
4.輸入組織Id 和包名點擊下一步
5. 點擊Finished 之后我們可以看到這樣一個目錄結構
注意:
紅色報錯是因為沒有引入servlet-api.jar,我們稍后處理
由於這個模板文件比較陳舊,因此我們需要做個修改。
6.Package 視圖下,項目右鍵——Build Path -----> Configure Build Path...
7. 切換到Libraries 視圖,點擊Remove ,移除這個陳舊的JRE 依賴類庫
8.點擊添加類庫
9. 選中JRE System Library
10.選中工作空間默認的JRE,點擊Finished ,關閉對話框。
11. 之后會自動變成這樣的目錄結構
Tips:
我們可以對比看到比之前多了兩個文件夾
src/main/java
src/main/test 文件夾
12. 下載 Axis2.war 樣例模板
http://axis.apache.org/axis2/java/core/download.html
13.下載后用好壓將這個*.war 解壓,
14. WEB-INF/lib 目錄下有一些說明文件,我們需要刪掉,只留下*.jar 即可
15.用命令行進入這個解壓目錄,我們需要刪除所有的*.txt 文件,輸入以下dos 命令即可
del *.txt
執行效果如下:
16. 我們可以看到所有的txt 文件已經被刪掉了
17. 復制所有解壓的文件到剛才創建的項目webapp 文件夾下
最后將WEB-INF/lib 下的jar 添加到build path 中就可以了。
當然也可以使用Maven 來管理,我花了點時間整理了下,貼出來
POM.xml
View Code<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.xingyun</groupId> <artifactId>axis2-webapp-pojo-sample</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>axis2-webapp-pojo-sample Maven Webapp</name> <url>http://maven.apache.org</url> <!-- 該項目支持Tomcat 7.0 + JDK1.8+ --> <dependencies> <!-- Axis2 Framework start --> <!-- activation-1.1.jar --> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>${activation.version}</version> </dependency> <!-- antlr-2.7.7.jar https://mvnrepository.com/artifact/antlr/antlr --> <dependency> <groupId>antlr</groupId> <artifactId>antlr</artifactId> </dependency> <!-- apache-mime4j-core-0.7.2 https://mvnrepository.com/artifact/org.apache.james/apache-mime4j-core --> <dependency> <groupId>org.apache.james</groupId> <artifactId>apache-mime4j-core</artifactId> <version>${apache.mime4j.core.version}</version> </dependency> <!-- axiom axiom-api-1.2.21.jar --> <dependency> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-api</artifactId> <version>${axiom.version}</version> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <!-- axiom-dom-1.2.21.jar --> <dependency> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-dom</artifactId> <version>${axiom.version}</version> </dependency> <!-- axiom-impl-1.2.21.jar --> <dependency> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-impl</artifactId> <version>${axiom.version}</version> </dependency> <!-- axiom-jaxb-1.2.21.jar --> <dependency> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-jaxb</artifactId> <version>${axiom.version}</version> </dependency> <!-- axis2 axiom-adb-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-adb</artifactId> <version>${axis2.version}</version> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <!-- axis2-clustering-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-clustering</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-codegen-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-codegen</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-corba-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-corba</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-fastinfoset-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-fastinfoset</artifactId> <version>${axis2.version}</version> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <!-- axis2-jaxbri-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-jaxbri</artifactId> <version>${axis2.version}</version> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <!-- axis2-jaxws-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-jaxws</artifactId> <version>${axis2.version}</version> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <!-- axis2-jibx-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-jibx</artifactId> <version>${axis2.version}</version> <exclusions> <exclusion> <groupId>org.jibx</groupId> <artifactId>jibx-bind</artifactId> </exclusion> <exclusion> <groupId>com.google.code.findbugs</groupId> <artifactId>bcel-findbugs</artifactId> </exclusion> </exclusions> </dependency> <!-- axis2-json-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-json</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-kernel-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-kernel</artifactId> <version>${axis2.version}</version> <exclusions> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> </exclusions> </dependency> <!-- axis2-metadata-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-metadata</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-mtompolicy-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-mtompolicy</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-saaj-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-saaj</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-soapmonitor-servlet-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-soapmonitor-servlet</artifactId> <version>${axis2.version}</version> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <!-- axis2-spring-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-spring</artifactId> <version>${axis2.version}</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </exclusion> </exclusions> </dependency> <!-- axis2-transport-base-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-base</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-transport-http-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-http</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-transport-jms-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-jms</artifactId> <version>${axis2.version}</version> <exclusions> <exclusion> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jms_1.1_spec</artifactId> </exclusion> <exclusion> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jta_1.0.1B_spec</artifactId> </exclusion> </exclusions> </dependency> <!-- axis2-transport-local-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-local</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-transport-mail-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-mail</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-transport-tcp-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-tcp</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-transport-udp-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-udp</artifactId> <version>${axis2.version}</version> </dependency> <!-- axis2-transport-xmpp-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-xmpp</artifactId> <version>${axis2.version}</version> <exclusions> <exclusion> <groupId>jivesoftware</groupId> <artifactId>smack</artifactId> </exclusion> <exclusion> <groupId>jivesoftware</groupId> <artifactId>smackx</artifactId> </exclusion> <exclusion> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> </exclusion> </exclusions> </dependency> <!-- axis2-xmlbeans-1.7.9.jar --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-xmlbeans</artifactId> <version>${axis2.version}</version> </dependency> <!-- Common Codec commons-codec-1.2.jar https://mvnrepository.com/artifact/commons-codec/commons-codec --> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> </dependency> <!-- commons-fileupload-1.3.3.jar https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>${commons.fileupload.version}</version> </dependency> <!-- commons-httpclient-3.1.jar https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient --> <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>${commons.httpclient.version}</version> </dependency> <!-- commons-io-2.1.jar https://mvnrepository.com/artifact/commons-io/commons-io --> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>${commons.io.version}</version> </dependency> <!-- commons-logging-1.1.1.jar https://mvnrepository.com/artifact/commons-logging/commons-logging --> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>${commons.logging.version}</version> </dependency> <!-- geronimo-annotation_1.0_spec-1.1.jar https://mvnrepository.com/artifact/org.apache.geronimo.specs/geronimo-annotation_1.0_spec --> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-annotation_1.0_spec</artifactId> <version>${geronimo.annotation.1.0.spec.version}</version> </dependency> <!-- geronimo-jaxws_2.2_spec-1.0.jar https://mvnrepository.com/artifact/org.apache.geronimo.specs/geronimo-jaxws_2.2_spec --> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jaxws_2.2_spec</artifactId> <version>${geronimo.jaxws.2.2.spec.version}</version> </dependency> <!-- geronimo-jta_1.1_spec-1.1.jar https://mvnrepository.com/artifact/org.apache.geronimo.specs/geronimo-jta_1.1_spec --> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jta_1.1_spec</artifactId> <version>${geronimo.jta.1.1.spec.version}</version> </dependency> <!-- geronimo-saaj_1.3_spec-1.0.1.jar https://mvnrepository.com/artifact/org.apache.geronimo.specs/geronimo-saaj_1.3_spec --> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-saaj_1.3_spec</artifactId> <version>${org.apache.geronimo.specs.version}</version> </dependency> <!-- geronimo-stax-api_1.0_spec-1.0.1.jar https://mvnrepository.com/artifact/org.apache.geronimo.specs/geronimo-stax-api_1.0_spec --> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-stax-api_1.0_spec</artifactId> <version>${org.apache.geronimo.specs.version}</version> </dependency> <!-- geronimo-ws-metadata_2.0_spec-1.1.2.jar https://mvnrepository.com/artifact/org.apache.geronimo.specs/geronimo-ws-metadata_2.0_spec --> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-ws-metadata_2.0_spec</artifactId> <version>${geronimo.ws.metadata.2.0.spec.version}</version> </dependency> <!-- gson-2.1.jar https://mvnrepository.com/artifact/com.google.code.gson/gson --> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency> <!-- httpclient-4.5.3.jar https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> </dependency> <!-- httpcore-4.4.6.jar https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> </dependency> <!-- jaxb-api-2.2.6.jar https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api --> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> </dependency> <!-- jaxb-impl-2.2.6.jar https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl --> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>${com.sun.xml.bind.version}</version> </dependency> <!-- jaxb-xjc-2.2.6.jar https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-xjc --> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-xjc</artifactId> <version>${com.sun.xml.bind.version}</version> </dependency> <!-- jaxen-1.1.6.jar https://mvnrepository.com/artifact/jaxen/jaxen --> <dependency> <groupId>jaxen</groupId> <artifactId>jaxen</artifactId> </dependency> <!-- jaxws-tools-2.2.6.jar https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-tools --> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-tools</artifactId> <version>${com.sun.xml.bind.version}</version> <exclusions> <exclusion> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> </exclusion> </exclusions> </dependency> <!-- jettison-1.3.8.jar https://mvnrepository.com/artifact/org.codehaus.jettison/jettison --> <dependency> <groupId>org.codehaus.jettison</groupId> <artifactId>jettison</artifactId> <version>${jettison.version}</version> <exclusions> <exclusion> <groupId>stax</groupId> <artifactId>stax-api</artifactId> </exclusion> </exclusions> </dependency> <!-- jibx-run-1.2.jar https://mvnrepository.com/artifact/org.jibx/jibx-run --> <dependency> <groupId>org.jibx</groupId> <artifactId>jibx-run</artifactId> <version>${jibx.run.version}</version> <exclusions> <exclusion> <groupId>org.codehaus.woodstox</groupId> <artifactId>wstx-asl</artifactId> </exclusion> </exclusions> </dependency> <!-- jsr311-api-1.1.1.jar https://mvnrepository.com/artifact/javax.ws.rs/jsr311-api --> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> <version>${jsr311.api.version}</version> </dependency> <!-- juli-6.0.53.jar https://mvnrepository.com/artifact/org.apache.tomcat/juli --> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>juli</artifactId> <version>${juli.version}</version> </dependency> <!-- log4j-1.2.15.jar https://mvnrepository.com/artifact/log4j/log4j --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> <exclusions> <exclusion> <groupId>com.sun.jmx</groupId> <artifactId>jmxri</artifactId> </exclusion> <exclusion> <groupId>com.sun.jdmk</groupId> <artifactId>jmxtools</artifactId> </exclusion> <exclusion> <groupId>javax.jms</groupId> <artifactId>jms</artifactId> </exclusion> </exclusions> </dependency> <!-- mail-1.4.jar https://mvnrepository.com/artifact/javax.mail/mail --> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>${mail.version}</version> </dependency> <!-- mex-1.7.9-impl.jar private jar neethi-3.0.3.jar https://mvnrepository.com/artifact/org.apache.neethi/neethi --> <dependency> <groupId>org.apache.neethi</groupId> <artifactId>neethi</artifactId> <version>${neethi.version}</version> </dependency> <!-- stax2-api-3.1.1.jar https://mvnrepository.com/artifact/org.codehaus.woodstox/stax2-api --> <dependency> <groupId>org.codehaus.woodstox</groupId> <artifactId>stax2-api</artifactId> <version>${stax2.api.version}</version> <exclusions> <exclusion> <groupId>javax.xml.stream</groupId> <artifactId>stax-api</artifactId> </exclusion> </exclusions> </dependency> <!-- taglibs-standard-impl-1.2.5.jar https://mvnrepository.com/artifact/org.apache.taglibs/taglibs-standard-impl --> <dependency> <groupId>org.apache.taglibs</groupId> <artifactId>taglibs-standard-impl</artifactId> <version>${org.apache.taglibs.version}</version> </dependency> <!-- taglibs-standard-spec-1.2.5.jar https://mvnrepository.com/artifact/org.apache.taglibs/taglibs-standard-impl --> <dependency> <groupId>org.apache.taglibs</groupId> <artifactId>taglibs-standard-spec</artifactId> <version>${org.apache.taglibs.version}</version> </dependency> <!-- tribes-6.0.53.jar https://mvnrepository.com/artifact/org.apache.tomcat/tribes --> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tribes</artifactId> <version>${tribes.version}</version> </dependency> <!-- woden-core-1.0M10.jar https://mvnrepository.com/artifact/org.apache.woden/woden-core --> <dependency> <groupId>org.apache.woden</groupId> <artifactId>woden-core</artifactId> <version>${woden.core.version}</version> <exclusions> <exclusion> <groupId>javax.xml.stream</groupId> <artifactId>stax-api</artifactId> </exclusion> </exclusions> </dependency> <!-- woodstox-core-asl-4.2.0.jar https://mvnrepository.com/artifact/org.codehaus.woodstox/woodstox-core-asl --> <dependency> <groupId>org.codehaus.woodstox</groupId> <artifactId>woodstox-core-asl</artifactId> <version>${woodstox.core.asl.version}</version> <exclusions> <exclusion> <groupId>javax.xml.stream</groupId> <artifactId>stax-api</artifactId> </exclusion> </exclusions> </dependency> <!-- wsdl4j-1.6.2.jar https://mvnrepository.com/artifact/wsdl4j/wsdl4j --> <dependency> <groupId>wsdl4j</groupId> <artifactId>wsdl4j</artifactId> </dependency> <!-- xalan-2.7.0.jar https://mvnrepository.com/artifact/xalan/xalan --> <dependency> <groupId>xalan</groupId> <artifactId>xalan</artifactId> <version>${xalan.version}</version> <exclusions> <exclusion> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> </exclusion> </exclusions> </dependency> <!-- xmlbeans-2.6.0.jar https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans --> <dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> <version>${xmlbeans.version}</version> <exclusions> <exclusion> <groupId>stax</groupId> <artifactId>stax-api</artifactId> </exclusion> </exclusions> </dependency> <!-- xml-resolver-1.2.jar https://mvnrepository.com/artifact/xml-resolver/xml-resolver --> <dependency> <groupId>xml-resolver</groupId> <artifactId>xml-resolver</artifactId> <version>${xml.resolver.version}</version> <exclusions> <exclusion> <groupId>org.apache.ws.xmlschema</groupId> <artifactId>xmlschema-core</artifactId> </exclusion> </exclusions> </dependency> <!-- xmlschema-core-2.2.1.jar https://mvnrepository.com/artifact/org.apache.ws.xmlschema/xmlschema-core --> <dependency> <groupId>org.apache.ws.xmlschema</groupId> <artifactId>xmlschema-core</artifactId> <version>${xmlschema.core.version}</version> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <dependencyManagement> <!-- 解決版本沖突 --> <dependencies> <dependency> <groupId>antlr</groupId> <artifactId>antlr</artifactId> <version>2.7.7</version> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.2.6</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.5</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.3</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.4.6</version> </dependency> <dependency> <groupId>wsdl4j</groupId> <artifactId>wsdl4j</artifactId> <version>1.6.2</version> </dependency> <dependency> <groupId>jaxen</groupId> <artifactId>jaxen</artifactId> <version>1.1.6</version> </dependency> </dependencies> </dependencyManagement> <!-- config --> <properties> <java.version>1.8</java.version> <antlr2.version>2.7.7</antlr2.version> <activation.version>1.1</activation.version> <axis2.version>1.7.9</axis2.version> <axiom.version>1.2.21</axiom.version> <apache.mime4j.core.version>0.7.2</apache.mime4j.core.version> <commons.fileupload.version>1.3.3</commons.fileupload.version> <commons.httpclient.version>3.1</commons.httpclient.version> <commons.io.version>2.1</commons.io.version> <xmlschema.core.version>2.2.1</xmlschema.core.version> <xml.resolver.version>1.2</xml.resolver.version> <xmlbeans.version>2.6.0</xmlbeans.version> <xalan.version>2.7.0</xalan.version> <woodstox.core.asl.version>4.2.0</woodstox.core.asl.version> <woden.core.version>1.0M10</woden.core.version> <tribes.version>6.0.53</tribes.version> <org.apache.taglibs.version>1.2.5</org.apache.taglibs.version> <stax2.api.version>3.1.1</stax2.api.version> <neethi.version>3.0.3</neethi.version> <mail.version>1.4</mail.version> <log4j.version>1.2.15</log4j.version> <juli.version>6.0.53</juli.version> <jsr311.api.version>1.1.1</jsr311.api.version> <jibx.run.version>1.2</jibx.run.version> <jettison.version>1.3.8</jettison.version> <geronimo.ws.metadata.2.0.spec.version>1.1.2</geronimo.ws.metadata.2.0.spec.version> <com.sun.xml.bind.version>2.2.6</com.sun.xml.bind.version> <org.apache.geronimo.specs.version>1.0.1</org.apache.geronimo.specs.version> <geronimo.jta.1.1.spec.version>1.1</geronimo.jta.1.1.spec.version> <geronimo.jaxws.2.2.spec.version>1.0</geronimo.jaxws.2.2.spec.version> <geronimo.annotation.1.0.spec.version>1.1</geronimo.annotation.1.0.spec.version> <commons.logging.version>1.1.1</commons.logging.version> </properties> <!-- Build Config --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
可以先發布到tomcat 容器中
到這里第一步准備就完成了。
2. 了解 Axis2 Service 目錄結構
Axis2的服務器端可以部署在任何Servlet引擎上,站看我們剛才創建的項目可以看到如下項目結構:
代碼清單2:axis2.war的目錄結構
注意:
最重要的是 axis2.xml,它控制應用程序如何處理收到的消息,確定Axis2是否需要應用modules目錄中定義的任何模塊。
Axis2 管理控制台的登陸賬號密碼也在這個配置文件里面。
services 文件夾下可以放*.aar 文件,也可以放services.xml 文件
3. 部署POJO
方法一:通過ANT 生成 WSDL 文件
安裝配置ANT
接下來我們還需要安裝下Ant, 因為待會要通過ANT命令構建我們的Web Service.
1. 打開Ant 官網:https://ant.apache.org/bindownload.cgi
2. 我們可以看到當前可能是這樣的,我們下載最新版本。
Tips: 由於是windows 系統演示,因此我摸下載的是圖中所示的zip,如果是linux 系統可以下載 tar.xz 格式
3. 配置環境變量
新建一個系統環境變量
ANT_HOME
C:\Apps\apache-ant\apache-ant-1.10.5
如圖所示:
添加到Path 中
%ANT_HOME%\bin\
如圖所示:
驗證:
ant -version
安裝成功會像這樣
ANT編譯生成WSDL
要使用POJO(Plain Old Java Objects)部署服務,請執行以下步驟。
注意:這里我們使用官方給的樣例源碼中來演示
解壓下載的二進制文件,比如我的存放位置如下:
E:\open-source\axis2\axis2-1.7.9-bin\axis2-1.7.9\samples
我們打開那個quickstart 文件夾,命令行進入這個文件夾:
前面我們已經安裝配置好了ant 構建工具,因此這里只需要在命令行下通過鍵入以下內容就可以從quickstart目錄生成WSDL:
ant generate.wsdl
執行成功會顯示如下:
我們可以看到多了一個build 文件夾
點進去可以看到有一個WSDL 文件(WSDL, Web Services Description Language的簡寫 )
這個文件是 StockQuoteSevice.java Web Service 的描述文件
打開這個文件可以看下

<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://quickstart.samples/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:tns="http://quickstart.samples/" targetNamespace="http://quickstart.samples/"> <wsdl:types> <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://quickstart.samples/xsd"> <xs:element name="update"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="symbol" nillable="true" type="xs:string"/> <xs:element name="price" type="xs:double"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="getPrice"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="symbol" nillable="true" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="getPriceResponse"> <xs:complexType> <xs:sequence> <xs:element name="return" type="xs:double"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> </wsdl:types> <wsdl:message name="updateRequest"> <wsdl:part name="parameters" element="ns:update"/> </wsdl:message> <wsdl:message name="getPriceRequest"> <wsdl:part name="parameters" element="ns:getPrice"/> </wsdl:message> <wsdl:message name="getPriceResponse"> <wsdl:part name="parameters" element="ns:getPriceResponse"/> </wsdl:message> <wsdl:portType name="StockQuoteServicePortType"> <wsdl:operation name="update"> <wsdl:input message="tns:updateRequest" wsaw:Action="urn:update"/> </wsdl:operation> <wsdl:operation name="getPrice"> <wsdl:input message="tns:getPriceRequest" wsaw:Action="urn:getPrice"/> <wsdl:output message="tns:getPriceResponse" wsaw:Action="urn:getPriceResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="StockQuoteServiceSoap11Binding" type="tns:StockQuoteServicePortType"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> <wsdl:operation name="update"> <soap:operation soapAction="urn:update" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> </wsdl:operation> <wsdl:operation name="getPrice"> <soap:operation soapAction="urn:getPrice" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="StockQuoteServiceSoap12Binding" type="tns:StockQuoteServicePortType"> <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> <wsdl:operation name="update"> <soap12:operation soapAction="urn:update" style="document"/> <wsdl:input> <soap12:body use="literal"/> </wsdl:input> </wsdl:operation> <wsdl:operation name="getPrice"> <soap12:operation soapAction="urn:getPrice" style="document"/> <wsdl:input> <soap12:body use="literal"/> </wsdl:input> <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="StockQuoteServiceHttpBinding" type="tns:StockQuoteServicePortType"> <http:binding verb="POST"/> <wsdl:operation name="update"> <http:operation location="update"/> <wsdl:input> <mime:content type="application/xml" part="parameters"/> </wsdl:input> </wsdl:operation> <wsdl:operation name="getPrice"> <http:operation location="getPrice"/> <wsdl:input> <mime:content type="application/xml" part="parameters"/> </wsdl:input> <wsdl:output> <mime:content type="application/xml" part="parameters"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="StockQuoteService"> <wsdl:port name="StockQuoteServiceHttpSoap11Endpoint" binding="tns:StockQuoteServiceSoap11Binding"> <soap:address location="http://localhost:8080/axis2/services/StockQuoteService"/> </wsdl:port> <wsdl:port name="StockQuoteServiceHttpSoap12Endpoint" binding="tns:StockQuoteServiceSoap12Binding"> <soap12:address location="http://localhost:8080/axis2/services/StockQuoteService"/> </wsdl:port> <wsdl:port name="StockQuoteServiceHttpEndpoint" binding="tns:StockQuoteServiceHttpBinding"> <http:address location="http://localhost:8080/axis2/services/StockQuoteService"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
Tips: 這個WSDL 文件可以用Ant 命令根據java代碼生成,也可以通過services.xml 配置經過瀏覽器訪問URL 生成。
方法二:通過URL訪問生成WSDL 文件
接下來我們就嘗試通過URL訪問生成WSDL 文件
打開我們自己創建的工程,我們需要在services 目錄下創建一個文件夾 StockQuoteService
注意:這個名字必須和services.xml 中name 節點的值保持一致。
其次還需要創建一個META-INF 文件夾,將我們的services.xml 放進去(這個文件可以在樣例源碼中找到)
文件路徑:C:\Apps\axis2\axis2-1.7.9\samples\quickstart\resources\META-INF\services.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="StockQuoteService" scope="application" targetNamespace="http://quickstart.samples/"> <description> Stock Quote Service </description> <messageReceivers> <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/> <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </messageReceivers> <schema schemaNamespace="http://quickstart.samples/xsd"/> <parameter name="ServiceClass">samples.quickstart.service.pojo.StockQuoteService</parameter> </service>
其次創建的web service Java源碼部分結構如下
這個StockQuoteService.java 文件可以在樣例源碼中找到
文件路徑:E:\open-source\axis2\axis2-1.7.9-bin\axis2-1.7.9\samples\quickstart\src\samples\quickstart\service\pojo\StockQuoteService.java
文件內容如下:

/* * 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. */ package samples.quickstart.service.pojo; import java.util.HashMap; public class StockQuoteService { private HashMap<String,Double> map = new HashMap<String,Double>(); public double getPrice(String symbol) { Double price = (Double) map.get(symbol); if(price != null){ return price.doubleValue(); } return 42.00; } public void update(String symbol, double price) { map.put(symbol, new Double(price)); } }
Tips: 為了去掉警告,我做了簡單修改,當然不修改也沒問題
部署發布到tomcat 或者其他web 容器成功后可以看到
然后通過查看以下服務列表來檢查以確保服務已正確部署:
http://localhost:8080/axis2-webapp-pojo-sample/services/listServices
我們可以看到除了默認的Version Services 之外,我們自定義的Web Service 也部署上去了。
您還可以在以下位置查看WSDL:
http://localhost:8080/axis2-webapp-pojo-sample/services/StockQuoteService?wsdl
訪問成功如下所示:
the schema 在
http://localhost:8080/axis2-webapp-pojo-sample/services/StockQuoteService?xsd
URL正常工作后,快速測試服務。嘗試將瀏覽器指向以下URL:
http://localhost:8080/axis2-webapp-pojo-sample/services/StockQuoteService/getPrice?symbol=IBM
我們將收到以下響應:
如果我們調用更新方法,
http://localhost:8080/axis2-webapp-pojo-sample/services/StockQuoteService/update?symbol=IBM&price=100.00
Tips: 但是由於更新方法是沒有返回值的,因此頁面可能看不到什么變化
然后執行第一個getPrice URL,您將看到價格已更新。
效果如下所示:
本篇完~