Sat 26 Jan 2008
Jersey REST Web Service in Glassfish
Posted by admin under Java , glassfish , jersey , programming , rest , software , webserviceComments Off
It seems to me that there are basically two ways to get started with the examples of the Jersey distribution (see also Java Webservices – Relationship between JAX-WS, JAX-RS, Metro and Jersey) in Glassfish.
First you can use the Glassfish’s update center executing:
$path/updatecenter/bin$ ./updatetool
like described for example in Japod’s blog.
But currently only version 0.4 is available here.
The other way is : download and unzip the newest version of Jersey. In the root directory of the unzipped archive you will find an
ant script, execute it like this:
$path/jersey-0.5-ea$ ant -f jersey-on-glassfish.xml -Dgf.home=$HOME/bin/glassfish install
with appropriate gf.home property supplied.
If you get an error message similiar to this one:
BUILD FAILED
/home/kostja/Development/jersey/jersey-0.5-ea/jersey-on-glassfish.xml:103: The following error occurred while executing this line:
/home/kostja/Development/jersey/jersey-0.5-ea/jersey-on-glassfish.xml:43: /home/kostja/Development/jersey/jersey-0.5-ea/examples/GlassfishDB not found.which means some example is missing in the distribution, edit the jersey-on-glassfish.xml file, comment out the matching lines:
<!-- copy-example example.name="GlassfishDB"/> <update-nb-prop nb.prop.file="${gf.home}/jersey/examples/GlassfishDB/nbproject/project.properties"/ -->
Be aware! This procedures will only install the examples and won’t add auto-magically the jersey jars to Glassfish’s runtime classpath. So
you have to take care by yourself to include the jars to the build target, see the provided examples for the jars needed:
glassfish/jersey/examples/SimpleServlet/nbproject/build-impl.xml:
<target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir"> <copy file="${file.reference.activation.jar}" todir="${build.web.dir}/WEB-INF/lib"/> <copy file="${file.reference.jsr250-api.jar}" todir="${build.web.dir}/WEB-INF/lib"/> <copy file="${file.reference.persistence-api-1.0.jar}" todir="${build.web.dir}/WEB-INF/lib"/> <copy file="${file.reference.asm-3.1.jar}" todir="${build.web.dir}/WEB-INF/lib"/> <copy file="${file.reference.jsr311-api.jar}" todir="${build.web.dir}/WEB-INF/lib"/> <copy file="${file.reference.jersey.jar}" todir="${build.web.dir}/WEB-INF/lib"/> </target>
glassfish/jersey/examples/SimpleServlet/nbproject/project.properties:
# some of this properties are set by jersey-on-glassfish.xml # during installation ashome.jersey.lib.dir=../../lib ashome.lib.dir=../../../lib ... file.reference.jsr250-api.jar=${ashome.jersey.lib.dir}/jsr250-api.jar ... file.reference.jersey.jar=${ashome.jersey.lib.dir}/jersey.jar ... javac.classpath=${file.reference.servlet.jar}\:${file.reference.activation.jar}\:${file.reference.jsr250-api.jar}\: ${file.reference.persistence-api-1.0.jar}\:${file.reference.asm-3.1.jar}\:${file.reference.jsr311-api.jar}\: ${file.reference.jersey.jar}