Reputation: 1696
I am trying to use Jersey with Grizzly as self-hosting
Basically my main is:
org.glassfish.jersey.server.ResourceConfig rc = new ResourceConfig();
rc.registerClasses(DummyController.class);
webServer = GrizzlyHttpServerFactory.createHttpServer(uri, rc, false);
System.out.println("Server Created");
try {
webServer.start();
System.out.println("Server Started");
} catch (IOException e) {
}
I have created a small Controller:
@Path("/")
public class DummyController {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String get() {
return "Got it!";
}
}
However, when I am running it, I am getting an exception:
Exception in thread "main" java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:309)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:289)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:331)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:141)
at RestServer.Server.main(Server.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
When I am not adding the resource the grizzly server runs ok but i cannot access any controller
I have used Maven to download all the dependencies
this is the pom file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TestRestServer</groupId>
<artifactId>TestRestServer</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-framework</artifactId>
<version>2.3.18</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly2</artifactId>
<version>1.18.3</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.18.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-servlet</artifactId>
<version>2.15</version>
</dependency>
</dependencies>
Upvotes: 3
Views: 3600
Reputation: 16041
The solution was changing the dependency from com.sun.jersey
to org.glassfish.jersey
in the pom.xml
. The first contains the implementation of the JAX-RS 1.x API (part of Java EE 6), the latter contains the JAX-RS 2.0 API implementation (part of Java EE 7).
Upvotes: 6