Warning:
The procedure described below apparently does not work. I have tried the same thing today (after erasing the .netbeans* directories in my home directory) and there is something missing I think in the 1.4 Jersey library to get this working.
Recently, I have picked up the work on the Jersey View Client module again. Especially I am interested in combining the JAX-RS server side with Jersey's client side framework.
Given that I am really positively impressed by Java EE 6 (thanks to Adam Bien and a bunch of his great presentations) and its integration into NetBeans that natural couple seemed like the way to go.
Turns out it was a lot harder than I thought!
The problem with using NetBeans/Java EE 6 for Jersey View Client development is that there is a really tight (and useful) integration between NetBeans, JAX-RS and GlassFish. Given that Jersey 1.5 is ahead of JAX-RS some work has to be done to get rid of the integrated stuff and add the latest, greatest Jersey builds.
Here is the approach I found to be the least painful:
(This has been tried with NetBeans 6.9.1, GlassFish 3.0.1 and Jersey 1.5)
Install Netbeans 6.9.1
Download Java Version of Netbeans 6.9.1 from netbeans.org and install. You skip this of course, if you have NetBeans already. I just want to describe from a defined starting point and actually re-installed mine to walk through the whole thing.
Remove GlassFish JAX-RS libraries
Remove some libraries distributed with Glassfish as described in 12.2 of Jersey User Guide. The description is not related to NetBeans but the following steps assume you are doing all this inside the GlassFish directory part of your NetBeans installation. For example, /Applications/NetBeans/glassfish-3.0.1/ on my MacBook Pro machine.
Download Jersey 1.5 GlashFish-ready Package
Download Jjersey-gfv3-core-1.5, unzip and copy JARs into the /glassfish/modules/ directory inside the NetBeans-GlassFish installation.
Download Jersey 1.5 View Client Package
Download Jersey View Client 1.5 and install in that same /glassfish/modules directory.
Create a New NetBeans Library for the Jersey JARs
From the Tools menu choose Library and click on New Library to create a new library. Name it restlib_jersey15 (or whatever you like).
Add the following JARs to the classpath by selecting them from the NetBeans-GlassFish modules directory where you have previously copied them to:
- jackson-jaxrs.jar
- jersey-core.jar
- jersey-client.jar
(I am only working on the list now, there are definitely some JARs missing)
I tried to keep it to a minimum to only put those JARs in there that you will need for building. The ones necessary at runtime are in GlassFish already anyway. For that reason, you might need to add to restlib_jersey15 if you have compile time dependencies not being resolved.
Create Example Application
Create new Java Web - Web Application project (with dependency-injection-enabled-box checked if you need it).
In that project, create a new REST resource class: write a class with a method and annotate that with @GET.
For the compiler to be able to resolve the use of @GET you need to add the library you created above to the project libraries folder (right-click on Libraries folder and then choose Add Library.
During the next build, NetBeans should perform its built-in REST integration magic, asking you about the application's resource path configuration. Use the default action and click OK.
The build process triggered by this will pull in some other REST library (I have not been able to figure out where to disable that). Simply remove those and they usually do not get added again.
Now you are all set to start playing with Jersey Client Views.
Notes
There is probably more that can be done. Especially there seems to be a way to overwrite the REST-related project properties to directly use the library you created instead of the JAX-RS 1.1. one. However, after one day of trying, I gave up. It seems to be hard wired at some point inside NetBeans. Any help on this would be greatly appreciated.
If you find I made any mistakes or if it works differently for your setup, please let me know.
0 comments:
Post a Comment