1

All, I have a little REST project to learn REST. Following is pom.xml providing jars for Jersey and Javax. I use Tomcat 8.

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.9</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.1.12</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>
</dependencies>

When I try to run any of web services, I receive the following error.

I Google searched it and in most places, it says that it’s a maven dependency/conflict issue bet. Jersey and JAX-RS API jars. I cannot find out what jars may conflict.

Please note that I had no problem running these services a while ago… started to receive this error when I changed my laptop… upgraded to Tomcat 8, installed Eclipse Luna, still on Java 7.

I can’t figure out what might have gone wrong… please let me know if you have any idea. Any help is greatly appreciated.

exception

javax.servlet.ServletException: Servlet execution threw an exception
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

    : Servlet.service() for servlet [Jersey Servlet] in context with path            [/restfulAPI] threw exception [Servlet execution threw an exception] with root cause
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
    at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:662)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
blueSky
  • 649
  • 5
  • 13
  • 31
  • 2
    Get rid of the the Java EE api jar. It uses JAX-RS 2. Jersey 1, uses JAX-RS 1. You might be trying to use some JAX-RS 2 APIs, while Jersey 1 doesn't support it. Jersey 1 already pulls in jsr311, which is JAX-RS 1 api jar. Also, probably not a problem, but don't mix Jersey versions. 1.9 and 1.10 not much of a difference, but no reason to mix them. – Paul Samsotha Mar 19 '15 at 01:28
  • Removed the Java EE api jar and added javax.ws.rs::jsr311-api::1.1.1 jar instead. The above exp. went away. When used the jersey-server 1.10 jar, got: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer. Put the jersey-server::1.9 jar back and it worked at it used to be. – blueSky Mar 20 '15 at 22:25
  • Yeah sorry, I think starting 1.10, the servlet container is in a new `jersey-servlet` jar – Paul Samsotha Mar 22 '15 at 01:40

3 Answers3

3

Although I don't know why it used to work with Tomcat 6 and started giving the above exception when upgraded to Tomcat 8, however, removed:

javaee-api 7.0

jar and added:

<dependency> 
    <groupId>javax.ws.rs</groupId> 
    <artifactId>jsr311-api</artifactId> 
    <version>1.1.1</version> 
</dependency>

The above exception went away. In order to have the consistency bet. Jersey client and server jars, used:

jersey-server 1.10

jar but received this error:

java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

When put the:

jersey-server 1.9

back, exception went away and the REST services started working again.

Please note, if your application, needs other jars from javaee-api, add each jar individually; looks like javaee-api package jar can't co-exist with Jersey 1.

blueSky
  • 649
  • 5
  • 13
  • 31
0

HI have faced the issue using weblogic 10.3 then i have just removed the javax.ws jar and its dependencies then my application is running fine

user3465058
  • 41
  • 1
  • 7
0

I got this when upgrading jersey 1.17 -> 1.19. Tried jersey 2 but the examples did not work. After considerable time I downgraded to 1.17.