AbstractMethodError using UriBuilder on JAX-RS
AbstractMethodError
are thrown when an application tries to call an abstract method.
uri
is an abstract method in UriBuilder
, so you need an implementation of this. This method (with String
parameter) is from version 2.0
of JAX-RS specification.
You're trying to use JAX-RS 2.0 with Jersey 1.*. Instead, you need to use Jersey 2.* that implements JAX-RS 2.0 and contains an implementation to uri
method.
In your pom.xml
you may remove these dependencies:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m12</version>
</dependency>
And use these dependencies:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.17</version>
</dependency>
Using this, uri
method is implemented in JerseyUriBuilder
class from jersey-common
.
EDIT:
You need to change, in your web.xml
, servlet com.sun.jersey.spi.container.servlet.ServletContainer
to org.glassfish.jersey.servlet.ServletContainer
and init-param
from com.sun.jersey.config.property.packages
to jersey.config.server.provider.packages
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri
You're using both Jersey 1 & 2
(Jersey 1 is an explicit dependency, Jersey 2 is a transitive dependency of jersey-test-framework-provider-jdk-http
) and that's not possible - so the classloader
is picking up the wrong URIBuilder
class.
The Jersey
dependencies in group
com.sun.jersey
are all Jersey version 1
. Jersey version 2
uses the group org.glassfish.jersey
.
You have both in your Maven
dependencies which is causing this problem.
If possible only use Jersey 2
.
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
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.
AbstractMethodError: javax.ws.rs.core.UriBuilder.uri in REST, EJB Application
You have multiple dependencies in your classpath that contains javax.ws.rs.core.UriBuilder
, two of JAX-RS 1.1:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.18</version>
</dependency>
And one of JAX-RS 2.0:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
Since JAX-RS 2.0 is from Java EE 7, probably you need downgrade javaee-api
to version 6, using like this:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>
Other way is upgrade Jersey version, like in this answer: AbstractMethodError using UriBuilder on JAX-RS
In runtime UriBuilder#uri(String) is called, so you need to verify the dependencies in the servlet container.
AbstractMethodError with URI Builder
You might have got your issue fixed, but actual problem is
The uri
method is an abstract method in UriBuilder
from version 2.0 of JAX-RS specification.
You're trying to use JAX-RS 2.0
with Jersey 1.*
. Instead, you need to use Jersey 2.*
that implements JAX-RS 2.0
and contains implementation of uri
method.
Related Topics
Session.Connection() Deprecated on Hibernate
If(False) VS. While(False): Unreachable Code VS. Dead Code
"Comparison Method Violates Its General Contract!" - Timsort and Gridlayout
Exception in Initializer Error in Java When Using Netbeans
How to Bundle Images in Jar File
Httpservletrequest - Setcharacterencoding Seems to Do Nothing
This: Cannot Use This in Static Context
Hibernate:How Override an Attribute from Mapped Super Class
Java Jtree Directory Structure from File Paths
Termination of Program on Main Thread Exit
Question About "Java Concurrency in Practice" Example
How to Do an Integer.Parseint() for a Decimal Number
Performance Difference Between a Wild Card Import and the Required Class Import
How to Set Oracle's Java as the Default Java in Ubuntu
Is Gnu's Java Compiler (Gcj) Dead