The Jersey package is Sun’s reference implementation of the JAX-RS standard for RESTful web services. It’s easy to use; with a few annotations, you’ll have your own REST api. The examples show how to use the included Grizzly server, allowing you to create embedded servers. That is, instead of fussy XML configurations for the large web servers, you can create small, easily deployable servers that you control via REST calls.
Using eclipse, just create your project, adding the jars required by Jersey. Follow the Getting Started guide for an example.
To deploy, you can package your project into a single jar using “File | Export…” Then you can run the jar using
java -Xmx512m -jar MyServer.jar
where you use -Xmx to make sure your server has enough memory. There’s just one problem…
When you run the jar, the program will start up cleanly. But when you hit it with a url, you see
The ResourceConfig instance does not contain any root resource classes.
followed by some exception. The problem is the server can’t find your classes. The simple trick is to add your bin directory to your classpath. Use “Project | Properties | Java Build Path.” On the Libraries tab, click “Add External Class Folder…” and add the “bin” directory in your project root.
Next time you run, you’ll see
Scanning for root resource and provider classes in the packages:
main
Root resource classes found:
class main.MyClass1Resource
class main.MyClass2Resource
class main.MyClass3Resource
class main.MyClass4Resource
as the embedded Grizzly server scans the package (”main”) you gave it when you initialized it:
initParams.put(”com.sun.jersey.config.property.packages”, “main”);
Instant RESTful server, one line deploy. What’s not to love?