I am trying to build a very basic Restful server in Eclipse using jersey and GrizzlyHttpServerFactory
. Below is the code:
The server
package com.example.rest;
class WebServr{
public static final String BASE_URI = "http://localhost:8080/myapp/";
public static HttpServer startServer() {
// create a resource config that scans for JAX-RS resources and providers
// in com.example.rest package
final ResourceConfig rc = new ResourceConfig().packages("com.example.rest");
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
}
public static void main( String[] args ) {
WebServr wb = new WebServr();
wb.startServer();
}
}
The rest component
package com.example.rest;
@Path("/amp")
@Produces("text/html")
public class Endpoint{
@GET
@Path("/test")
public Response test() {
return Response.ok().entity("SUCCESS").build();
}
}
But when I create a simple “jar” file by exporting my compiled java files using above code, I can see my server is running(can see output in netstat –an | grep port) but my restful client is returned with “404 error”(though I can see a new http connection is being established at server side). But when I create a jar file using eclipse option of “Runnable jar”, it works perfectly fine(my client is served properly). Can anyone give any suggestion why it is happening.