大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 hot資訊 Tomcat發布Web Service

Tomcat發布Web Service

更新時間:2021-12-27 11:02:12 來源:動力節點 瀏覽878次

1.下載jax-ws依賴包

因tomcat沒有jax-ws所需的依賴環境,所以第一步先下載Jax-ws RI,即jax-ws reference implemantation, 地址:http://jax-ws.java.net。

2.安裝jax-ws RI到tomcat服務器

先下載ant與tomcat,設置環境變量ANT_HOME與CATALINA_HOME,然后在path下引入各自的bin目錄打開命令提示符,在jax-ws ri包的目錄下運行ant install。

此命令會直接把需要的包導入到${tomcat}\shared\lib目錄下,其實也就是把jaxws RI lib下的包復制到了tomcat安裝目錄下shared\lib里面。

3.設置Eclipse中的tomcat

由于eclipse是自己定義的tomcat配置文件,所以需要加些東西,把shared\lib加入進來,打開ctalina.properties文件。

打開后為(節選):

# 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.  
  
#  
# List of comma-separated packages that start with or equal this string  
# will cause a security exception to be thrown when  
# passed to checkPackageAccess unless the  
# corresponding RuntimePermission ("accessClassInPackage."+package) has  
# been granted.  
package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.  
#  
# List of comma-separated packages that start with or equal this string  
# will cause a security exception to be thrown when  
# passed to checkPackageDefinition unless the  
# corresponding RuntimePermission ("defineClassInPackage."+package) has  
# been granted.  
#  
# by default, no packages are restricted for definition, and none of  
# the class loaders supplied with the JDK call checkPackageDefinition.  
#  
package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.    
#  
#  
# List of comma-separated paths defining the contents of the "common"  
# classloader. Prefixes should be used to define what is the repository type.  
# Path may be relative to the CATALINA_HOME or CATALINA_BASE path or absolute.  
# If left as blank,the JVM system loader will be used as Catalina's "common"  
# loader.  
# Examples:  
#     "foo": Add this folder as a class repository  
#     "foo/*.jar": Add all the JARs of the specified folder as class  
#                  repositories  
#     "foo/bar.jar": Add bar.jar as a class repository  
common.loader=${catalina.home}/shared/lib/*.jar,${catalina.home}/shared/lib,${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar  

找到common.loader配置項增加${catalina.home}/shared/lib/*.jar,${catalina.home}/shared/lib 這兩個路徑即可

4.建立項目

新建一個web項目,webservice_web

HelloService.java是提供web service的一個接口,代碼如下:

package com.zxuqian.webservice;  
import javax.jws.WebMethod;  
import javax.jws.WebService;    
@WebService  
public interface HelloService {         
      @WebMethod  
     String greetings (String name);    
}  

HelloServiceImpl.java是實現類,代碼如下:

package com.zxuqian.webservice.impl;   
import javax.jws.WebService;   
import com.zxuqian.webservice.HelloService;   
@WebService (endpointInterface = "com.zxuqian.webservice.HelloService" )  
public class HelloServiceImpl implements HelloService {    
      @Override  
      public String greetings(String name) {  
            return "Hello: " + name;  
     }    
}  

5.添加sun-jaxws.xml

sun-jaxws.xml是通過web方式發布web service應用的描述文件,內容如下:

<?xml version="1.0" encoding="UTF-8"?>  
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">  
    <endpoint name="HelloWorld" implementation="com.zxuqian.webservice.impl.HelloServiceImpl"   
        url-pattern="/hello" />  
</endpoints>  

各個節點的具體說明請參考下載的jaxws ri包里面的docs文檔,在這里簡單說明一下,endpoint需要指定

web service服務的接口和實現類,以及它的url相對路徑

6.配置web.xml

內容如下:

<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">  
  <display-name>webservice_web</display-name>      
  <listener>  
    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>  
  </listener>  
  <servlet>  
    <servlet-name>hello</servlet-name>  
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>  
    <load-on-startup>1</load-on-startup>  
  </servlet>      
  <servlet-mapping>  
    <servlet-name>hello</servlet-name>  
    <url-pattern>/hello</url-pattern>  
  </servlet-mapping>  
</web-app>  

7.測試

啟動tomcat,在瀏覽器中輸入web service地址 http://localhost:8088/webservice_web/hello我的tomcat的端口號是8088,大家根據自己的端口號進行相應的修改。

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 波多野结衣中文一区二区免费 | 久久久久9 | 国产国产成人精品久久 | 91精品日韩| 免费的爱爱视频 | 久久国产精品免费看 | 很黄很色的免费视频 | 亚洲网站视频 | 人人爱天天做夜夜爽毛片 | 精品亚洲永久免费精品 | 国产美女久久久久久久久久久 | 国产毛片久久精品 | 2019年国产高清情侣视频 | 天天操天天摸天天碰 | 视频一区精品 | 丝袜亚洲精品中文字幕一区 | 99视频全部看免费观 | 久久亚洲精品久久久久 | 天天做天天添天天谢 | 久久精品视频网 | 中文字幕一区在线观看 | 午夜影院0606| 国产区视频在线 | 亚洲日本免费 | 看欧美毛片一级毛片 | 国产99精品一区二区三区免费 | 综合色图| 看黄a大片 免费 | 日韩成人黄色片 | 色涩亚洲 | 久久精品国产亚洲欧美 | 成人亚洲国产综合精品91 | 日韩高清性爽一级毛片免费 | 四虎成人精品在永久在线观看 | 欧美成人性videos | 欧美午夜在线观看 | 中国女人和老外的毛片 | 国产欧美亚洲精品第3页在线 | 欧美乱淫视频 | 一级毛片成人免费看a | 国产精品99一区二区三区 |