Tuesday, February 26, 2008

A Rant about GlassFish and Jersey

So you want to play around with Web Services, both SOAP and REST? Maybe you've had your fill of WSO2's Mashup Server, drooled over its strengths (XML processing and service exposure) and understood its limitations (legacy resource connectivity including persistence - no, Data Services didn't cut it for me). Now you want to look at a more conventional, Java-based (as opposed to JavaScript-based) server.

I had attended a Sun Tech Day many months ago when they demonstrated the GlassFish JEE app server and its REST implementation called Jersey. I had also heard a lot about Sun's advanced SOAP/WS-* stack, Project Tango. One of my consultant colleagues (a REST advocate, no less) showed me a Tango demo he had put together and was himself impressed with the policy-driven interoperability that it made possible.

So it was with fond visions of being able to build a Domain Model using Java objects and then expose the domain as services using both SOAP/WS-* and REST paradigms from the same box that I downloaded GlassFish.

The GlassFish Quickstart Guide gave me my first indications of trouble.

Why would you have instructions labelled Step 1 and Step 2 if there's something you need to do before either of them? (Shouldn't that at least be labelled Step 0?)
1. Add the install-dir/bin/ directory to the PATH environment variable.
2. Start the server by entering this command: asadmin start-domain domain1.

After searching in vain for the "bin" directory under the directory where I had installed (well, unzipped) GlassFish, I found this line above the two steps listed:

Once you install using "ant -f setup.xml", you start the server by starting the domain.
Casually, just in passing. Why they didn't just say
Step 0: Install GlassFish using "ant -f setup.xml"
beats me.

So I finally installed GlassFish and started up a "domain" from the command line. (All right, I'll go with your idiosyncrasies, although why I should know about "domains" and why you couldn't just give me a Linux "startup.sh" script and a Windows "startup.bat" script beats me once again.)

Oh, then I found that Jersey doesn't come bundled with GlassFish. I'd have to get that separately.

No problem, GlassFish has a tool called "Update Center", which lets you download modules like Jersey automatically.

Uh-oh. Update Center doesn't work through proxies. (You idiot, configure the proxy settings in the tool.) I did that. The "doesn't work" comment refers to after I configured my proxy settings in Update Center. And I didn't get a meaningful error message either, so I had no clue how to fix the problem, if indeed the problem was my fault. (These guys are starting to bug me.)

OK, good news, bad news. It appears from someone else's experience that Update Center only shows you older versions of Jersey, not the very latest one, so you can't use it anyway. You'll need to download and install Jersey manually.

All right, so I downloaded Jersey and ran the recommended script

$ ant -f jersey-on-glassfish.xml
-Dgf.home=$HOME/bin/glassfish install

Got the predicted error message, edited "jersey-on-glassfish.xml" and commented out the offending line. (Seriously Sun, even teeny-tiny Open Source projects provide working code. Why can't you?)

Finally got the ant script to work.

Hold on! Turns out there's something more. A lot more. To quote Drop By,
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:
Okay-doke. I ran
ant -f build-impl.xml library-inclusion-in-archive
I got an error with a TaskDef of all things. Some class (I forget what it was now) wasn't found, although it should have been. That's when I finally gave up.

There's simply no excuse for the abysmal state of readiness of GlassFish and Jersey. I know Jersey isn't yet at version 1.0, but GlassFish is at version 2.1, for goodness sake! In contrast, WSO2's Mashup Server worked, and worked pretty well, way back in the days of version 0.2. It was trivial to install and get running, the examples worked, and all my test examples worked as well. There were some problems that I faced, but those were when I had gone well past the basic stuff and started pushing the envelope.

I don't know if I have the time and patience to try GlassFish and/or Jersey again. It's just too hard.


pelegri said...

Feedback received! I'll contact the jersey and the update center folks, and also will get a review started on the documentation. As you point out, there are some very things that are very easy to do that can help a lot.

Don't give up on us yet. - eduard/o

Ganesh Prasad said...

OK! It's nice to know someone's listening. I'll wait for your updates.



pelegri said...

Paul says there was a glytch on the Jersey upgrade to the UC. He is on vacation tomorrow and Jakub is away all this week, so it may take a few days to get that part resolved. I'll let you know about the others as they progress. - eduard/o

sandoz said...

Death by a thousand cuts! Sorry about the Jersey glitch for the GF install script that slipped into the stable 0.5 version on java.net (i have now fixed it in the latest 0.6 build).

As i understand it Jersey 0.5 was pushed to the update center as an incompatible release from 7th Feb.

Jersey 0.6 will be available on the update center soon after we make the stable release on March 7th (there is a delay for the UC since we have to package the UC GF bits and push them to the update center).

The reason we cannot currently deliver Jersey with GF is because of a legal restriction of bundling non-final JSR APIs/impls with products. Also Jersey is on about a 6 week release cycle where for each release we update the JAX-RS API with the latest EG agreed stuff so that developers can test the JAX-RS API and provide feedback.

Note that as a very quick way to get started with Jersey you can download it and use it without a Web container, see the HelloWorld example.

If you have the patience for a second try i would be very interested in hearing any feedback (good or bad) on Jersey. Not all feedback is bad :-) see this email sent today to the users list:



Ganesh Prasad said...


Thanks for the prompt response. Yes, I would be very eager to try Jersey again. I'm a Java developer by background, and very interested in REST, so Jersey would be the most natural product for me to use.

I'll try it again and let you know how I go.


rajeshwar said...

Ganesh, Thanks for sending the logs and other details. We are looking into it. There is already a open bug for this (https://updatecenter.dev.java.net/issues/show_bug.cgi?id=349).


Ganesh Prasad said...


I tried running Jersey 0.6 as you suggested. I went to the HelloWorld example and typed 'ant' because 'run' was the default task. The example worked when I went to http://localhost:9998/helloworld, but the ant messages were somewhat scary, and at first I thought the build had failed. Here's what I got:

Buildfile: build.xml





















[javac] Compiling 2 source files to C:\usr\local\jersey-0.6-ea\examples\Hell



[java] 29/02/2008 15:25:04 com.sun.ws.rest.api.core.ClasspathResourceConfig
[java] INFO: Scanning for root resource and provider classes in the paths:
[java] C:\usr\local\jersey-0.6-ea\lib\jsr173_api.jar
[java] C:\usr\local\jersey-0.6-ea\lib\mail.jar
[java] C:\usr\local\jersey-0.6-ea\lib\activation.jar
[java] C:\usr\local\jersey-0.6-ea\lib\jaxb-api.jar
[java] C:\usr\local\jersey-0.6-ea\lib\jaxb-impl.jar
[java] C:\usr\local\jersey-0.6-ea\lib\jdom-1.0.jar
[java] C:\usr\local\jersey-0.6-ea\lib\rome-0.9.jar
[java] C:\usr\local\jersey-0.6-ea\lib\jettison-1.0-RC1.jar
[java] C:\usr\local\jersey-0.6-ea\lib\http.jar
[java] C:\usr\local\jersey-0.6-ea\lib\asm-3.1.jar
[java] C:\usr\local\jersey-0.6-ea\lib\jsr311-api.jar
[java] C:\usr\local\jersey-0.6-ea\lib\jersey.jar
[java] C:\usr\local\jersey-0.6-ea\examples\HelloWorld\build\classes
[java] 29/02/2008 15:25:05 com.sun.ws.rest.api.core.ClasspathResourceConfig
[java] INFO: Root resource classes found:
[java] class com.sun.ws.rest.samples.helloworld.resources.HelloWorldResou
[java] 29/02/2008 15:25:05 com.sun.ws.rest.api.core.ClasspathResourceConfig
[java] INFO: Provider classes found:
[java] class com.sun.ws.rest.impl.container.servlet.JSPTemplateProcessor
[java] 29/02/2008 15:25:05 com.sun.ws.rest.impl.application.ComponentProvid
erCache getComponent
[java] WARNING: The provider class, class com.sun.ws.rest.impl.container.se
rvlet.JSPTemplateProcessor, could not be instantiated

[java] Server running
[java] Visit: http://localhost:9998/helloworld
[java] Hit return to stop...

Alexis said...

Are you at Sun Tech Days this week?
Drop by the GlassFish booth or come to GlassFish Day tomorow (Th).


Ganesh Prasad said...


Thanks, I'll certainly do so.


jpeters said...

Hi Ganesh,

Don’t you think your being a little hard on glassfish? Step six of the GlassFish Installations Instructions clearly state “If you do not want clustering capabilities, run the following command:”

ant -f setup.xml

The Quickstart guide is not the Installation Instructions. I found the instructions very informative and well written for an Open Source project.

Jeff Peters
www.xaware.org >

Ganesh Prasad said...

> Don’t you think you're being a little hard on glassfish?

Maybe I am. That's why it's called a rant ;-).

But I guess the point is not so much that there's no clear instruction to run 'ant -f setup.xml'. It's the fact that there's no ready-to-run startup script in a bin directory. Look at other servers. Tomcat has a startup.sh script. JBoss has a run.sh script. Is that so hard to provide? Why bother the user with 'ant -f setup.xml'?


pelegri said...

I'm with you Ganesh. There are some obvious things that we (GF) could be doing, the simplest being to at least include a README file! I have a short list of things that should be able to do by GFv2.1 this summer.

- eduard/o

sandoz said...

Hi Ganesh,

The verbose logging messages are deliberate, i like to be verbose for an early access to make problem solving easier, as we get close to FCS i will move the logging category to something higher (like config). You can change the default logging if you want to stop these messages.

The specific warning you highlighted is meant to happen when the servlet API is not in the class path. When you don't have JAXB in the classpath you will get a warning about WADL. These warnings are useful because Jersey is very loose about the runtime dependencies (you put in your classpath what you need, see docs/dependencies.html for more details).

Hope this helps,

Ganesh Prasad said...


I understand. I was just a bit scared to see the warning about the class not found, that's all.

In spite of my initial problems, I think Jersey is coming together quite well, and the support your team has shown is impressive. Jersey should be terrific by the time it hits 1.0.


275 said...

HI Ganesh,

I am trying to see how the Jersey examples work for understanding REST implementation cocept.

But you said we need to comment an offending line in jerseyforglassfish.xml file.

Can you please let me know what that line is. I am a bit new to Java and XML..and thats why I am aksing you.

also did u try to work on Jersey later. If so what steps you have followed to make jersey work on glassfish.


Ganesh Prasad said...

Hi Jyothsna,

This is the website that alerted me to the line that needed commenting:



Ganesh Prasad said...


And no, I haven't had the chance to try Jersey on GlassFish again. It's on my to-do list.


275 said...
This comment has been removed by the author.
275 said...

Thanks Ganesh,

I will try based on that and see if it works..

Will update you if I am able to make Jersey work.

Some examples are already working like bookstore. but the examples which have Post/put/delete methods are not working and as u mentioned in your post, I am also getting the provider class could not be instantiated and not found errors.

Trying the Jersey 0.7 version now.

Thanks for your prompt reply.