2012-10-27 45 views
0

引導類加載器加載,我知道這是JAX-WS Web服務的非常簡單的例子,但我不能夠解決這個錯誤。我下面這個教程http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat/ 和使用的build.xml使用螞蟻做出的戰爭文件。但是,當我複製粘貼此war文件到Apache Tomcat的webapps目錄下,它就會被部署,但這個網址本地主機:8084 /的HelloWorld /你好給出錯誤404(我的Apache Tomcat的端口號8084上運行)。我已經包含下面的戰爭文件的內容:java.lang.LinkageError的:JAXB 2.1 API正在從JAX-WS Web服務

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, 
Inc.//DTD Web Application 2.3//EN" 
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd"> 

<web-app> 
    <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> 
    <session-config> 
     <session-timeout>120</session-timeout> 
    </session-config> 
</web-app> 

太陽jaxws.xml

<?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.mkyong.ws.HelloWorldImpl" 
     url-pattern="/hello"/> 
</endpoints> 

的build.xml

<project name="HelloWorld" default="dist" basedir="."> 
    <description> 
     Web Services build file 
    </description> 
    <!-- set global properties for this build --> 
    <property name="src" location="src"/> 
    <property name="build" location="build"/> 
    <property name="dist" location="dist"/> 
    <property name="webcontent" location="WebContent"/> 

    <target name="init"> 
     <!-- Create the time stamp --> 
     <tstamp/> 
     <!-- Create the build directory structure used by compile --> 
     <mkdir dir="${build}"/> 
    </target> 

    <target name="compile" depends="init" 
    description="compile the source " > 
     <!-- Compile the java code from ${src} into ${build} --> 
     <javac srcdir="${src}" destdir="${build}"/> 
    </target> 

    <target name="war" depends="compile" 
    description="generate the distribution war" > 

    <!-- Create the war distribution directory --> 
    <mkdir dir="${dist}/war"/> 

    <!-- Follow standard WAR structure --> 
    <copydir dest="${dist}/war/build/WEB-INF/" src="${webcontent}/WEB-INF/" /> 
    <copydir dest="${dist}/war/build/WEB-INF/classes/" src="${build}" /> 

    <jar jarfile="${dist}/war/HelloWorld-${DSTAMP}.war" basedir="${dist}/war/build/"/> 
    </target> 

</project> 

HelloWorld.java

package com.mkyong.ws; 

import javax.jws.WebMethod; 
import javax.jws.WebService; 
import javax.jws.soap.SOAPBinding; 
import javax.jws.soap.SOAPBinding.Style; 

//Service Endpoint Interface 
@WebService 
@SOAPBinding(style = Style.RPC) 
public interface HelloWorld{ 

    @WebMethod String getHelloWorldAsString(); 

} 

HelloWorldImpl.java

package com.mkyong.ws; 

import javax.jws.WebService; 

//Service Implementation Bean 

@WebService(endpointInterface = "com.mkyong.ws.HelloWorld") 
public class HelloWorldImpl implements HelloWorld{ 

    @Override 
    public String getHelloWorldAsString() { 
     return "Hello World JAX-WS"; 
    } 
} 

請指出我要去的地方錯了

編輯:我在Tomcat的日誌以下異常:

SEVERE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloWorld]] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) 
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1105) 
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1664) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) 
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContainerInitializer 
    at java.lang.ClassLoader.findBootstrapClass(Native Method) 
    at java.lang.ClassLoader.findBootstrapClass0(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1629) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) 
    at java.lang.ClassLoader.loadClassInternal(Unknown Source) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Unknown Source) 
    at org.apache.catalina.startup.ContextConfig.getServletContainerInitializer(ContextConfig.java:1655) 
    at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1565) 
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1273) 
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878) 
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369) 
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) 
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    ... 11 more 
Nov 4, 2012 5:25:35 PM org.apache.catalina.startup.HostConfig deployDirectory 
SEVERE: Error deploying web application directory F:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\HelloWorld 
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloWorld]] 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:904) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) 
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1105) 
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1664) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) 
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
+0

請有人幫忙 我想開發web服務 – user1717415

+0

你的代碼看起來沒問題,所以我懷疑你的ant build配置已經壞了。在tomcat啓動過程中,您沒有在日誌中看到任何錯誤/異常? – kolossus

+0

感謝您的回覆。我在tomcat日誌中添加了異常 – user1717415

回答

3

您遇到這個錯誤的由於程序需要的庫版本與JDK默認發佈的版本之間的差異導致的結果。您正在運行的JAX-WS 2.2(2.2需要最少的JAXB版)web服務的例子,但你的JDK 6和Tomcat安裝附帶JAXB 2.1版本,從而導致你有例外。

要解決此問題,使用JDK的endorsed standards override mechanism,基本上可以讓你覆蓋默認的庫/被打包成一個香草安裝的JDK與同較新版本的一部分罐子。

  1. 下載在<JDK_HOME>\lib\endorsed路徑,其中<JDK_HOME>指的是你的JDK(我在這裏假設窗口)的安裝文件夾中的JAXB apiJAX-WS庫和地方的最新副本。如果該路徑中不存在endorsed文件夾,請創建該文件夾並在其中放置新副本。

  2. 採取相同的下載發生在你的tomcat安裝你<TOMCAT_HOME>\endorsed\路徑。如前所述,如果endorsed不存在,請創建它。

你是好,如果你使用的是JDK版本6或更低去

+0

非常感謝kolossus的回覆。我跟着你的步驟,聯繫錯誤消失了!但現在有一些其他例外(編輯原始問題的例外)。請幫我解決這個問題 – user1717415

+0

@ user1717415,由於兩個相關原因,tomcat啓動可能會失敗1. jar'servlet.jar'可能存在於tomcat文件夾中的多個位置。驗證是不是這種情況,並確保該jar只存在於'TOMCAT_HOME/lib'文件夾中 – kolossus

+0

我有TOMCAT_HOME/lib文件夾中包含的servlet-api.jar文件 – user1717415

0

。升級它。 我在升級JDK serion到7之後遇到了同樣的問題。