Reputation: 2917
My simple REST based webservice does encounter a problem when I try do run it. It seems that the deployment succeeds, but when I access the servlet I get this error:
WARNING: StandardWrapperValve[MySimpleServer]: Servlet.service() for servlet MySimpleServer threw exception
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:790)
My root pom.xml is very simple and just contains these dependencies and plugins:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
<build>
<finalName>MySimpleServer</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
<version>3.1</version>
</plugin>
</plugins>
</build>
The web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>MySimpleServer</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MySimpleServer</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Actually, it worked earlier today and I have not made any changes at all to the pom.xml file. Is it something with Glassfish4 server? I have made a clean build, redeployed the servlet, restarted GlassFish etc. Nothing helps.
Upvotes: 1
Views: 496
Reputation: 6721
I've had this problem when I've accidentally mixed Jersey
/ JAX-RS
versions - IE having both Jersey 1 & 2 libs on the classpath
.
I can't see how this happens with just the three dependencies in your pom
, but I'm quite sure this is happening somewhere.
Looking at your stacktrace
, I can see this is what's happening.
This is javax.ws.rs-api/2.0
UriBuilder.java
118 public static UriBuilder fromUri(String uriTemplate) {
119 return newInstance().uri(uriTemplate);
120 }
Which is exactly what you're getting - a call to UriBuilder.uri(String)
on line 119
.
Looking at the equivalent line numbers in the UriBuilder
source from Jersey 1.8
and it's a Javadoc
comment for a different method.
So, you've somehow got jax-rs 2 on your classpath and it's causing this problem.
Maybe you have it on a shared / common classloader, or a stray lib lying around.
UPDATE
Yes - glassfish ships with Jersey / JAX-RS libs. See this question
As an aside - if you're able, I'd upgrade to Jersey 2. Hope this helps
Will
Upvotes: 1