Reputation: 4868
I currently try out the Grizzly-Framework 2.3.6. I am using the following maven dependency:
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-framework</artifactId>
<version>2.3.6</version>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-server</artifactId>
<version>2.3.6</version>
</dependency>
I can start a server with the following code example:
HttpServer server = HttpServer.createSimpleServer();
try {
server.start();
addJaxRS(server);
System.out.println("Press any key to stop the server...");
System.in.read();
} catch (Exception e) {
System.err.println(e);
}
I added the following JAX-RS Class:
@Path("/helloworld")
public class HelloWorldResource {
@GET
@Produces("text/plain")
public String getClichedMessage() {
return "Hello World";
}
}
My question is: how can I tell grizzly to add the HelloWorldRessoruce as a JAX-RS Resource?
Upvotes: 1
Views: 6199
Reputation: 4868
I found a solution by changing the dependency to "jersey-grizzly2" which includes the grizzly version 2.2.16
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly2</artifactId>
<version>1.17.1</version>
</dependency>
</dependencies>
I can now start grizzly with my JAX-RS resources like this:
import java.io.IOException;
import org.glassfish.grizzly.http.server.HttpServer;
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.api.core.ResourceConfig;
public class Main {
public static void main(String[] args) throws IOException {
// HttpServer server = HttpServer.createSimpleServer();
// create jersey-grizzly server
ResourceConfig rc = new PackagesResourceConfig("my.resources");
HttpServer server = GrizzlyServerFactory.createHttpServer(
"http://localhost:8080", rc);
try {
server.start();
System.out.println("Press any key to stop the server...");
System.in.read();
} catch (Exception e) {
System.err.println(e);
}
}
}
But I initially thought that jersey is part of Grizzly?
Upvotes: 6