Java Developer's Kit (JDK) set-up for Eclipse

Russell Bateman
September 2014
last update:

Table of Contents

Introduction
Eclipse installation
Eclipse-JDK layout
How I get a Sun JDK
How I get a openJDK
Wire up JDK to Eclipse
eclipse.ini
Add installed JDK to workspace
Installing Tomcat for use with Eclipse
Upgrading Eclipse
Uninstalling Eclipse
 

I began using Eclipse to develop application in 2005. Over the years I've used Europa, Ganymead, Galileo, Helios, Indigo, Juno, Kepler, Luna and Mars on the following platforms:

  • Windows XP and 7
  • openSuSE 10
  • Ubuntu Karmic, Lucid and Precise
  • Mint 13 and 17
  • Fedora 20, 22 with Cinnamon

I have used the following JDKs for development over the years:

  • Sun Java 1.4, 1.5, 1.6, 1.7, 1.8
  • openJDK 1.6, 1.7

Installing Eclipse

Note that in the Eclipse Mars timeframe, a formal installer was created for use with Eclipse. I have never used this (don't feel a need to) and so little to nothing in this page deals with that experience. However, the principle of a finished installation remains relevant.

Unless you're certain the platform you're installing requires a specially built Eclipse from the distributor, never obtain your Eclipse from anywhere but eclipse.org. (Please note that I do not use the Eclipse installer for Mars that came out in Spring 2015. I do not advise against it; I have just never used it.)

Choose an Eclipse package that's already as close to what you wish to do with it as possible:

- Eclipse IDE for Java Developers
- Eclipse IDE for Java EE Developers
- Eclipse IDE for C/C++ Developers
- Eclipse IDE for PHP Developers
- etc.

Eclipse is a personal productivity tool. Unless you're doing something very clever, like setting it up in a classroom situation, resist the temptation to put it on paths like

- /opt
- /usr/bin/local
- C:\Program Files
- etc.

Instead, put at:

- /home/jack/eclipse
- /home/jill/devtools/eclipse
- C:\Users\sebastien\eclipse
- etc.

In short, put it somewhere over which you have complete control and you will find bliss in your life.

Eclipse-JDK layout

If you're going to develop Java software, you must download a JDK because this is what gives you Javadoc in Eclipse ContentAssist. I do not download and install a JDK for my whole computer. I leave my computer's idea of a JRE to be whatever it wants. I let it install and update separately from my Eclipse usage. I have a peculiar way of setting up a JDK as illustrated here.

How I get a Sun JDK

As noted and as you should see from my diagram, I do not blindly install a JDK over the top of whatever my computer is using as a Java Runtime Environment (JRE). I make a separate copy. This is so my host is not disturbed in the natural update of its JRE. That JRE gets updated whenever it wants to be. More than that, it is so that when I run Eclipse, I know what version of the JDK I'm running and it never changes unless and until I decide it will.

Steps

  1. Go to http://java.sun.com. This gets me what you see here:

  2. As shown, click on Java for Developers.

  3. I scroll down the page a bit because I've decided I'm not going to get a copy of Java SE 8u20, the current JRE/JDK, but instead the last Java 7:

  4. As shown, click on the Download button underneath JDK.

  5. Click to accept the license agreement, then find your platform. Mine's Linux x64 and I'm just going to download the tarball named jdk-7u67-linux-x64.tar.gz. If I were running Windows 7, I'd choose the 64-bit Windows, self-extracting archive, jdk-7u67-windows-x64.exe:

  6. I save the tarball to my path /home/russ/dev and explode it, then discard the tarball:
    ~/dev $ tar -zxf jdk-7u67-linux-x64.tar.gz
    ~/dev $ rm jdk-7u67-linux-x64.tar.gz
    ~/dev $ ll -d jdk1.7.0_67
    drwxr-xr-x 8 russ russ 4096 Jul 25 10:51 jdk1.7.0_67
    

    Note that this isn't a zip on Windows, but a self-extracting archive with a .exe extension. At some point during extraction, you can choose where to put it (instead of clobbering the JRE installed on your Windows machine). Put it on a path such as the one(s) I suggested earlier—in a personal location under your user.

How I install openJDK

This is a rather more advanced undertaking so I won't illustrate it here, but give some links to notes to peruse. Why would you use this instead of Sun's JDK? Because your company, for whatever reason, has a legal or moral aversion to Oracle software. I usually use the Sun version, but I've had little trouble at all with the openJDK.

Wire up Java to Eclipse

This is exactly what I need to run Eclipse. I just need to accomplish 2 things:

  1. I'll doctor eclipse.ini, according to http://wiki.eclipse.org/Eclipse.ini to point to my JDK. I could run Eclipse off my host's JRE, but I'll just run it off the JRE inside the JDK I just downloaded. This Eclipse Wiki page explains how to set up eclipse.ini whether for Windows, Linux or Macintosh. In my case, in bold below, I've added this. If left to its own devices, Eclipse might very well find my host's JRE, but this way I'm telling it what to use.
    eclipse.ini
    ~/dev $ cat eclipse/eclipse.ini
    -startup
    plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
    --launcher.library
    plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20130521-0416
    -product
    org.eclipse.epp.package.jee.product
    --launcher.defaultAction
    openFile
    -showsplash
    org.eclipse.platform
    --launcher.XXMaxPermSize
    256m
    --launcher.defaultAction
    openFile
    --launcher.appendVmargs
    -vm
    /home/russ/dev/jdk1.7.0_67/bin/java
    -vmargs
    -Dosgi.requiredJavaVersion=1.6
    -XX:MaxPermSize=256m
    -Xms40m
    -Xmx512m
    
  2. Second, I'm going to inform Eclipse that I want to use my new JDK by default. This is a workspace setting, so it only holds for whatever workspace I'm in when running Eclipse at the time I do this:

    1. (Already running Eclipse...) I pull down Window → Preferences → Java then click on Installed JREs. I've been running JDK 1.7.0_45 and want to update it. (Even if this were the first installed JRE I was setting up, the steps would be the same.)

    2. Continuing, I click Add as shown, then Standard VM.

    3. Next

    4. Opposite the JRE home edit field, I click the Directory button to navigate to my new JDK, select it and click OK.

    5. I see this:

    6. I click Finish, see my two JDKs (if the first time, then there will only be 1). I ensure that the checkbox next to it is checked. I can also dump my old JDK if I want by selecting it and clicking Remove.

Installing Tomcat for use with Eclipse

I install Tomcat separately from any I might have on my computer for the same reason I don't want Eclipse to use my host's JRE. Also, I use Eclipse to deploy my web applications to Tomcat, the one it knows about. I don't usually debug web applications on a formally running Tomcat.

  1. Download Tomcat from here.

  2. Connect it to Eclipse much the same as was done for the JDK by:
    Window → Preferences → Server → Runtime Environments.

  3. Click Add, click the version of Tomcat you want to use, click Next, then Browse to the top of your exploded Apache Tomcat download and click OK.

  4. Click Finish.

Just JDKs, you can choose to tell Eclipse about as many as you wish. (You can also set up JBoss and other server containers too.) When you create a Server for the workspace, you can choose one or more of these, then launch them from the Servers view.

To use Tomcat or other server containers with Eclipse, you must have downloaded the Eclipse IDE for Java EE Developers package from eclipse.org or you can take the after-market route as described by How do I install WTP?.

Upgrading Eclipse

Especially if upgrading past one or more versions, download and install the new version you want (not on top of your existing version), then start it and point to your existing workspaces.

You can save preferences from your existing Eclipse installation to a file, then restore (import) them into the new version.

If you had third-party plug-ins and want them in the new version, you must go through Help → Eclipse Marketplace to find and install them again.

Uninstalling Eclipse

The only thing needed to uninstall Eclipse, no matter what OS your host is running, is to remove the following artifacts:

  1. the eclipse subdirectory that contains the Eclipse binary and everything else,
  2. .eclipse under your home subdirectory, if present, and
  3. .p2 under your home subdirectory, if present.