Setting up Java EE 6 SDK in Eclipse

Russell Bateman
20 May 2011
last update:

Introduction

The Java EE 6 SDK from Sun comes with new features for web developers such as

This document suggests one way to get these set up such that they may be consumed using Eclipse. It's odd that I've found no other intelligence on the web on how to do this. Maybe it's self-evident to everyone else; I figured it out and it wasn't too hard, but it seems useful to say something about it.

One unfortunate side effect of the download is that you get the whole Glassfish server container. I'm a Tomcat guy and so don't care for Glassfish. Still, it's a small price to pay to have to ignore that.

These instructions are given from a more Linux point of view, but I give a nod to Windoz sufferers in the text too.

How does Java 6 "include" JAX-RS?

Even using this JRE in Eclipse as-is will get you only the standard 9 JARs:

The way you get the "new, cool" stuff is via JARs that ship in what's more properly termed, "Glassfish". That is, the extra JARs, and there's a pile of them, come from another subdirectory of the download and you have to add them by hand. Still, this is somewhat simpler than digging around on the web for the, especially, in the case of anything from java.net, JARs that come from constantly changing download sites (such as has happened to java.net since purchase by Oracle.

Installation

<soapbox>
In fact, as always, I eschew actual installation of JDKs, SDKs, etc. in favor of consuming them locally. This means I insulate my computer host from anything but the common way of automatic updates to software on which even my non-development use depends (every day running of apps). I consume JDKs, copies of Tomcat, etc. from Eclipse pointing to my local user filesystem instead of potentially fluctuating paths out into territory such as /usr/local/bin (or C:\Program Files).
</soapbox>

  1. Download and install from Sun's Java EE Downloads to some convenient place in your filesystem.
  2.  
  3. Make the download executable since it's a self-extracting archive.
  4.  
  5. Specify a convenient installation subdirectory such as /home/russ/dev/glassfish3. On Windows this might be C:\Users\russ\dev\glassfish3.
  6.  
  7. Enable update (might be a mistake, but I tried it: the update process turned out to be somewhat inelegant on Linux--I even had to kill the process after it did its thing since it hung, but I think I got over it).
  8.  
  9. I used the common installation rather than the custom one.

Add to Eclipse

Eclipse maintains lists of important resources such as the JRE, Tomcat and other servers placing them at the disposal of the developer in each workspace. I already have JDK1.6.0-24 as my default JRE, so I added this as a separate JRE. Of course, except for the added JARs that come with Java EE 6 SDK, they are identical in function.

To add this to Eclipse, ...

  1. Go to Window -> Preferences -> Java -> Installed JREs -> Add -> Standard VM -> Next -> Directory.
  2.  
  3. Navigate to /home/russ/dev/glassfish3 and select jdk, then click OK.

Additional libraries advertised as part of Java 6

The ones that interest me (there are something like 237) include:

At this point, I experimented adding more of the accompanying JARs to the JRE since Eclipse permits that. However, I discovered subsequently, that it would not deploy them and I'd be missing symbols when attempting to run my application under Tomcat. Is this because in deployment, Eclipse doesn't deploy the JRE libraries as redundant?

Instead, I deployed the additional libraries separately, just as I've always been used to doing, into WebContent/WEB-INF/lib. I copied the JARs from /home/russ/dev/glassfish3/glassfish/modules/ to that path, then, in Build Path -> Libraries, I did this by clicking on Add External JARS..., browsing to the JARs under WebContent/WEB-INF/lib and adding each one.

If you leave out any libraries that are provided on the SDK path glassfish/modules, you can include them just as you would any other third-party JARs, but you'll have to remember to include them in your project's deployment assembly. Right-click on your project, choose Build Path -> Configure Build Paths, then check down the left side for Deployment Assembly. If you do not, you may be puzzled as to why a) your project doesn't seem to work when run from Eclipse and b) why the WAR file, once deployed to Tomcat, doesn't produce a working web application.