14

I am implementing rest easy web service and i am using jboss 4.0 but i am getting following exception...

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

my web.xml is

<?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>


locoyou
  • 1,697
  • 1
  • 15
  • 19
msg
  • 165
  • 1
  • 2
  • 10

2 Answers2

34

It's easy to meet such error when migrating/copying dependencies from servlet based project to standalone. For servlet based project one usually needs dependency with scope = 'provided' relying that servlet provides implementation:

Dependency causing error:

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0.1</version>
    <scope>provided</scope>
</dependency>

But for standalone projects there is no servlet implementation so you need to turn on copy javax.ws.rs-api to classpath. Usually you need just to remove <scope>provided</scope> line and have straightforward dependency:

Fixed dependency:

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0.1</version>
</dependency>
Alfishe
  • 3,430
  • 1
  • 25
  • 19
  • 1
    This was exactly my situation, and this solution was exactly my solution. Thank you. – user4052054 May 29 '17 at 16:14
  • 1
    an eye opener: https://stackoverflow.com/questions/32106428/jaxrs-api-vs-jsr311-api-vs-javax-ws-rs-api-vs-jersey-core-vs-jaxrs-ri also note that JAX-RS 2.1 is supported by Java 8 and above while JAX-RS 2.0 plays with Java 6. if JAX-RS 2.1 libraries are added to classpath and JBoss 4 runs on Java 6, they are simply ignored unless you use -verbose:class and watch for errors – hello_earth Apr 20 '22 at 13:17
3

From the Exception its clear that The class loader is not able to find the class Configuration (from javax/ws/rs/core/Configuration).

Please check classpath, corresponding JAR file and make sure that the class file exist.

Pandiri
  • 313
  • 1
  • 4