Java – Hello world by Jersey and Grizzly (from User Guide)
I'm looking at the Jersey user guide and trying to set up the Hello World sample using the Jersey web service and the embedded grizzly server
I'm completing section 1, "getting started." I have obtained the code example in Section 1.1 compilation:
// The Java class will be hosted at the URI path "/helloworld" @Path("/helloworld") public class HelloWorldResource { // The Java method will process HTTP GET requests @GET // The Java method will produce content identified by the MIME Media // type "text/plain" @Produces("text/plain") public String getClichedMessage() { // Return some cliched textual content return "Hello World"; } }
But then I will go to section 1.2 "deploying root resources", which is that I should set up an embedded grizzly web server to test my resources:
public class Main { public static void main(String[] args) throws IOException { final String baseUri = "http://localhost:9998/"; final Map<String,String> initParams = new HashMap<String,String>(); initParams.put("com.sun.jersey.config.property.packages","com.sun.jersey.samples.helloworld.resources"); System.out.println("Starting grizzly..."); SelectorThread threadSelector = GrizzlyWebContainerFactory.create(baseUri,initParams); System.out.println(String.format( "Jersey app started with WADL available at %sapplication.wadl\n” + “Try out %shelloworld\nHit enter to stop it...",baseUri,baseUri)); system.in.read(); threadSelector.stopEndpoint(); System.exit(0); } }
The problem is, it seems that the user guide has not been updated for the time being, and the grizzlywebcontainerfactory class no longer exists!
I'm using Jersey V 1.10 and grizzly V 1.9 forty-one
Can someone help me recreate this example? I know that I can run web services in containers. I am interested in running it through the simplest embedded server settings. In my project, I do not need additional resources (web. XML, etc.), but only two classes
Solution
I think the answer is that I need to include a Jersey grizzly dependency, and then I can follow the user guide
This is not specified in the required dependencies list provided in the user guide:
Thank Ryan Stewart for answering similar questions