这是我在stackoverflow中的第一个问题!哇:)
我在这个问题上失去了我的头发:( 我有一个简单的helloworld-Web服务,并构建warfile并将其部署在localhost的tomcat(8.0.35)上。 要清楚:我刚写了一个用@WebService注释的类;然后我写了web.xml和sun-jaxws.xml;我什么都没做!这个类是否足以成为Web服务?我是否想念另一步?
问题:url:localhost:8080 / endpointname / url-pattern没有显示我的Webservice的定义,因为它在我编写服务所遵循的链接中的含义:http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat/。我刚刚得到一个胖胖的404 Eror。这是我的构建文件:
<?xml version="1.0" encoding="UTF-8"?>
<project name="test_WS" default="deploy" basedir=".">
<property name="project-name" value="${ant.project.name}" />
<property name="war-file-name" value="${project-name}.war" />
<property name="source-directory" value="src" />
<property name="web-directory" value="WebContent" />
<property name="webinf.dir" value="${web-directory}/WEB-INF" />
<property name="web-xml-file" value="${webinf.dir}/web.xml" />
<property name="build-directory" value="build" />
<property name="shared.deploy.dir" value="C:/1_Entwicklung/datarocket/tomcat-webapps" />
<property name="local.deploy.dir" value="C:/1_Entwicklung/apache-tomcat-8.0.35/webapps" />
<tstamp prefix="build-info">
<format property="current-date" pattern="dd-MM-yyyy" locale="de" />
<format property="current-time" pattern="hh:mm:ss a z" locale="de" />
</tstamp>
<!-- Classpath -->
<path id="build.classpath">
<!-- Jax WS related -->
<fileset dir="${webinf.dir}/lib/" casesensitive="yes">
<include name="*.jar"/>
</fileset>
</path>
<target name="init">
<mkdir dir="${webinf.dir}/classes" />
<mkdir dir="${build-directory}/classes" />
</target>
<!-- deploy -->
<target name="deploy" depends="war">
<copy file="${build-directory}/${war-file-name}" todir="${local.deploy.dir}" />
<copy file="${build-directory}/${war-file-name}" todir="${shared.deploy.dir}" />
</target>
<!-- war -->
<target name="war" depends="build">
<war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}">
<classes dir="${build-directory}/classes" />
<fileset dir="${web-directory}">
<!-- exclude webxml as it is attribute of the war tag -->
<exclude name="WEB-INF/web.xml" />
</fileset>
<manifest>
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</war>
</target>
<target name="build" depends="clean">
<javac includeantruntime="false" srcdir="${source-directory}" destdir="${build-directory}/classes">
</javac>
</target>
<!-- clean -->
<target name="clean" description="Prepare for clean build">
<delete dir="${webinf.dir}/classes" />
<delete dir="${build-directory}" />
<mkdir dir="${build-directory}" />
<mkdir dir="${build-directory}/classes" />
</target>
</project>
这是我的sun-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="HalloAPI"
implementation="saab.javabeans.Hallo"
url-pattern="/sayhello" >
</endpoint>
</endpoints>
这就是API:
@WebService
public interface HalloAPI {
String sayHello(String name);
}
为什么tomcat说:“HTTP状态404 - / HalloAPI / sayhello”? 有关出版的错误或遗漏? 我的意思是,如果我使用glassfish-server,它会部署并向我展示tester-和wsdl。 但是在tomcat上部署......我得到了404。
这是我的web.xml:
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>test_WS</display-name>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>webservicesServlet</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>webservicesServlet</servlet-name>
<url-pattern>/sayhello</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
</web-app>
快乐我:我将所需的jaxws jars移动到web-inf / lib中。现在Tomcat不会在部署时抛出错误。但服务小瓶网址仍然无法使用。我所知道的:tomcat / lib中的jaxws-jars让类加载器混乱。所以我把他们打包进了战争。 现在是部署协议:
07-Jun-2016 15:34:54.149 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\1_Entwicklung\apache-tomcat-8.0.35\webapps\test_WS.war
07-Jun-2016 15:34:55.371 INFO [localhost-startStop-2] com.sun.xml.ws.transport.http.servlet.WSServletDelegate.<init> WSSERVLET14: Initialisierung von JAX-WS-Servlet
07-Jun-2016 15:34:55.372 INFO [localhost-startStop-2] com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized WSSERVLET12: Initialisierung von JAX-WS-Kontext-Listener
07-Jun-2016 15:34:55.373 INFO [localhost-startStop-2] com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized WSSERVLET12: Initialisierung von JAX-WS-Kontext-Listener
07-Jun-2016 15:34:55.385 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive C:\1_Entwicklung\apache-tomcat-8.0.35\webapps\test_WS.war has finished in 1,236 ms
问题仍然存在:服务不可用;状态:404 提前感谢您的帮助。
答案 0 :(得分:1)
将com.sun.xml.ws.transport.http。 S ervlet.WSServlet更改为 web.xml中的com.sun.xml.ws.transport.http。 s ervlet.WSServlet