java.lang.NoClassDefFoundError:javax / ws / rs / core / Configuration

时间:2015-01-14 09:24:39

标签: java web-services

我正在实施其他简单的Web服务,我正在使用jboss 4.0,但我得到了以下异常......

java.lang.NoClassDefFoundError: javax/ws/rs/core/Configuration

我的web.xml是

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>RestfulWebService</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- <servlet>
    <servlet-name>HelloServlet</servlet-name>
    <load-on-startup>1</load-on-startup>
</servlet> -->
<!-- <servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>javax.ws.rs.core.Application</servlet-class>
</servlet> -->
<listener>
    <listener-class>
   org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
    </listener-class>
</listener> 
<!-- <context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>true</param-value>
</context-param> -->

<servlet>
    <servlet-name>Resteasy</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>com.websevices.TestService</param-value>
    </init-param>
</servlet>
<!-- <servlet-mapping>
        <servlet-name>javax.ws.rs.core.Application</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping> -->
<servlet-mapping>
    <servlet-name>Resteasy</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<context-param>
            <param-name>resteasy.servlet.mapping.prefix</param-name>
            <param-value>/rest</param-value>


2 个答案:

答案 0 :(得分:22)

从基于servlet的项目迁移/复制依赖项到独立时,很容易遇到此类错误。对于基于servlet的项目,通常需要依赖于scope =&#39;提供的&#39;依赖servlet提供实现:

依赖性导致错误:

{{1}}

但是对于独立项目,没有servlet实现,因此您需要将javax.ws.rs-api复制到classpath。通常您只需删除&lt; scope&gt;提供的&lt; / scope&gt;并且具有直接的依赖性:

固定依赖:

{{1}}

答案 1 :(得分:2)

从Exception中可以看出,类加载器无法找到类Configuration(来自javax / ws / rs / core / Configuration)。

请检查classpath,相应的JAR文件,并确保该类文件存在。