web services - How to deploy a JAX-RS application on a Java SE environment? -


i want code restful web service jax-rs, , want publish on localhost http://localhost:[port]. read following in answer:

the java se 7 (jsr 336) , java se 8 (jsr 337) specifications don't incorporate jax-rs component. however, jax-rs applications can published in java se environments (using runtimedelegate) , jax-rs implementations may support publication via jax-ws.

the runtimedelegate mentioned. how can use it? if there examples on how achieve task, please share them me.

to deploy jax-rs application in java se environment, use runtimedelegate , http server supported jax-rs implementation. servlet container not required.

the jsr 339 states following:

in java se environment configured instance of endpoint class can obtained using createendpoint method of runtimedelegate. application supplies instance of application , type of endpoint required. implementation may support 0 or more endpoint types of desired type.

how resulting endpoint class instance used publish application outside scope of specification.

jersey, jax-rs reference implementation, supports range of http servers can use deploy jax-rs applications in java se.

for example, grizzly , runtimedelegate, can have following:

public class example {      public static void main(string[] args) {          resourceconfig resourceconfig = new resourceconfig();         resourceconfig.register(greetingsresource.class);          httphandler handler = runtimedelegate.getinstance()                 .createendpoint(resourceconfig, httphandler.class);          httpserver server = httpserver.createsimpleserver(null, 8080);         server.getserverconfiguration().addhttphandler(handler);          try {             server.start();             system.out.println("press key stop server...");             system.in.read();         } catch (exception e) {             system.err.println(e);         }     }      @path("/greetings")     public static class greetingsresource {          @get         @produces(mediatype.text_plain)         public string getgreeting(){             return "hello other side.";         }     } } 

the application available @ http://localhost:8080/greetings.

the following dependencies required example shown above:

<dependency>     <groupid>org.glassfish.grizzly</groupid>     <artifactid>grizzly-http-server</artifactid>     <version>2.3.30</version> </dependency> <dependency>     <groupid>org.glassfish.jersey.containers</groupid>     <artifactid>jersey-container-grizzly2-http</artifactid>     <version>2.25.1</version> </dependency> 

other supported implementations include:

jersey documentation describes other deployment alternatives java se environment without runtimedelegate.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -