Setting up the workspace
The first thing I like to do is to build a workspace that goes with Eclipse so I can setup all the settings in the workspace. Doing this for things like code formatting and templates ensures everyone’s code will look as similar as possible. There’s also a lot of other settings you may want to setup so no one else on your team will have to.
To do this just download the distribution of Eclipse you want to start with and unzip it (for this example I’m using Eclipse IDE for Java EE Developers version 3.5.1). Then start Eclipse. Since this is the first time you will be opening Eclipse it will prompt you for where you want your workspace to be. Just clear out want it in the box by default and type ‘workspace’ and check the box at the bottom that says ‘Use this as the default and do not ask again’. It should look like this:
Click OK. Eclipse will then create a folder called ‘workspace’ under your Eclipse folder. From now on when you open this Eclipse it will automatically use this folder as the workspace. Now you can install all the plug-ins you want and setup all the settings you want and they will be carried with this distribution.
Packaging the JDK
Another thing you may want to do is package a JDK up with the distribution so you know for sure that everyone is using the same one. Also, this means that Eclipse will run even if the person does not have any version of Java installed on their machine (this does introduce a platform dependency, though).
The easiest way to do this is to find a JRE you have already installed on your machine and just copy it into a folder called ‘jre’ under the Eclipse folder. When you run the eclipse.exe file it looks for a ‘jre’ folder in the Eclipse folder, if one is found, then it will launch using that JRE. However, this is often not preferable because some Eclipse plug-ins (like the Maven 2 plug-in) require you to be running Eclipse on a JDK not just a JRE. So it’s best to use a full JDK. You could just take a JDK and copy it into a folder named ‘jre’ under the Eclipse folder, but that could be misleading, and there’s another way.
Take a JDK you have on your machine and copy it to a folder called ‘jdk’ under your Eclipse folder. Also in that folder there is an eclipse.ini file that is used for setting certain parameters to the exe and the Java VM. Open that file and put these two lines at the top:
-vmThis will tell Eclipse to use the VM you put in the ‘jdk’ folder.
jdk/bin
Now you can just zip up the Eclipse folder and give it to your team.
Bonus: Bundling Gradle with the distribution
For my current project we are planning to use Gradle for our builds. I wanted to be able to bundle it with the Eclipse distribution and setup an external tool configuration so it would be easy to use for anyone else.
To do this I downloaded the latest version of Gradle and put it in a folder called ‘gradle’ under the Eclipse folder. Then, in Eclipse, I created an external tool configuration like this:
This will work fine as long as the person that uses it has their JAVA_HOME set to a valid JRE. But we’d rather have this work without that variable set. The gradle.bat file specifically looks for the JAVA_HOME variable to be set and will error out if it’s not. You can set this value to something using the Environment tab in Eclipse, but I couldn’t find any way to get this to work in a way that would function properly on everyone’s machine. So I ended up just modifying the gradle.bat file and adding a line that sets the JAVA_HOME variable to the ‘jdk’ folder under the Eclipse folder. The modified file looks like this (the added line is in bold):
...It’s a bit of a hack, but it works. If anyone has any better ideas, I’m surely open to it.
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.\
set JAVA_HOME=%DIRNAME:~0,-12%\jdk
...