Tips, Tweaks and being Productive with Eclipse

A personal guide on how to setup and configure the Eclipse IDE to save time and be more productive

Tips, Tweaks and being Productive with Eclipse

First Steps

Eclipse can be a mercurial beast. Given how infinitely extendable it is (and completely free to boot) it's nothing short of amazing. However, this extendability can lead to complaints of it being slow or overly complex.

Broken down below are all the tweaks, tips and configuration changes I perform on Eclipse Luna to make it nice and fast.

First things first, I'm going to assume you already have Java installed; if so then download the Eclipse zip file for your platform (in this example, Windows 7 64-bit with 16GB RAM and running Java 7) and extract it to the location you want to run it from (C:\eclipse).

Next, navigate to the Eclipse folder you chose and open up the eclipse.ini file in a text editor. It should look a little something like this:

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20140603-1326
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.6
-Xms40m
-Xmx512m

There are a couple of issues with this default configuration we are going to tweak.

Pinning that pesky Eclipse icon

I like to pin Eclipse to my windows task bar as I use it an awful lot in my day job. But you may have noticed when right clicking on the Eclipse icon once it's running that it does not give you the option to pin it. If you try right clicking on eclipse.exe and pinning it to the task bar that way, you will find it will pin it but you will get a duplicate icon once Eclipse has finished loading after the splash screen. To fix that we need to specify which VM Eclipse should use.

So right at the top of the file add the following:

-vm
C:/Program Files/Java/jre7/bin/server

The path to Java should obviously match your system. Now if you run Eclipse and right click on the icon you should get the option to pin it. If the right-click context menu still doesn't appear, try rebooting Windows and reloading Eclipse and it should appear. Eclipse pinned and no duplicate icons after the splash screen finishes, yay.

Performance tweaks

Next we are going to add some tweaks to the VM arguments that Eclipse uses to make it nice and nippy.

Locate the line -vmargs and directly beneath it add the following:

-server
-XX:PermSize=256m
-XX:MaxPermSize=256m
-XX:+UseParallelGC

Then at the bottom of the file lets allocate Eclipse a little more memory to play with. Edit the lines starting -Xms and -Xmx and change them to the following.

-Xms1024m
-Xmx1024m

I have 16GB RAM in my system; if you have less you can change the numbers to 512m instead. Just make sure you keep both numbers the same.

The complete file

When finished your file should look like the below. If so, save your file and close down your text editor.

-vm
C:/Program Files/Java/jre7/bin/server
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20140603-1326
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-vmargs
-server
-XX:PermSize=256m 
-XX:MaxPermSize=256m
-XX:+UseParallelGC
-Dosgi.requiredJavaVersion=1.6
-Xms1024m
-Xmx1024m

Preferences

Now we have Eclipse starting up nice and quickly and we have our icon staying exactly where we want it, we are going to tweak some of the preferences in Eclipse to give us a nicer time of it when writing code all day.

Content assist favourites

If you use a few static utilities such as Google's Guava or JUnit's assertions (you do write tests don't you?), then you may find Eclipse's auto-complete features a little lacking as it will fail to offer any methods from said utilities. To fix this, we can add them to Eclipse's content assist. Navigate to Window > Preferences > Java > Editor > Content Assist > Favorites[sic]. Then click New Type and enter the fully qualified class names for the static members you want auto-complete to help you with. In my case:

  • com.google.common.base.Preconditions
  • org.junit.Assert
  • org.mockito.Mockito

Content Assist Favourites

Now Eclipse will offer up the methods from these libraries on hitting CTRL-SPACE.

Save actions

One handy time saver is that you can get Eclipse to perform certain actions every time you save a file; such as applying your default formatting rules, or ensure your imports are all organised correctly. Simply go to Window > Preferences > Java > Editor > Save Actions. I generally opt for both of the above mentioned time savers as well as the additional options listed.

Save Actions

However, it might be better to opt for choosing to only format the edited lines, as once you go to check-in your code to source code control having a commit full of whitespace changes can be a bit of a pain!

Automatically save before a build

If like me, you are wearing out your left pinky and index finger by constantly hitting CTRL-S to make sure you don't lose anything you have written, save yourself a bit of time (and arthritis) by enabling the Save automatically before build option. Go to Window > Preferences > General > Workspace.

Save Automatically on Build

Text file encoding

If you have a work environment with lots of differing platforms that developers use, it's usually a good idea to set the default encoding used for all the files Eclipse creates to UTF-8. Click Window > Preferences > General > Workspace.

Encoding Options

Always launch the previously launched application

After about Eclipse 3.4 the Eclipse foundation changed the default behaviour of the run button. Previously, the button just launched whatever the last run launch configuration was. After 3.4, they changed it so Eclipse attempted to build and run whatever file you currently had selected. Fortunately you change this frankly odd behaviour back to when it made sense. Go to Window > Preferences > Run/Debug > Launching and select Always launch the previously launched application, et voila.

Always Launch

Now we have Eclipse running mostly how I like it, it's time we learnt how we can move around within our codebase whilst saving wear and tear on our precious mice. Eclipse has some very handy keyboard shortcuts that will have you whizzing round your code in no time.

Quick open CTRL-O

Quick Open lets you jump to specific elements within the Java file you currently have open. This saves you having to visually scan through the Outline View to locate what you need. It also supports wildcards and camel case searching.

Open type CTRL-SHIFT-T

This one is the biggest time saver. Having to dig through the Package Explorer any time you need to locate a particular class is a complete waste of time. Just hit CTRL-SHIFT-T and type the classname you need. Again, this supports wildcards and camel case to make searching even quicker.

Open Type

Open resource CTRL-SHIFT-R

If the file you want to open isn't a Java file, such as a properties file, then the way to bring them up quickly is through CTRL-SHIFT-R. Again, this works similarly to both of the above, and wildcards and camel casing is supported. However, there is also support for specifying which folder you want to search for particular files in; for example */icons/*.png will search for all PNG files within the icons folder of your project.

The marketplace

Lastly, Eclipse has a large ecosystem of plugins and extensions that can be accessed through the market place. Just click Help > Eclipse Marketplace. Below are the two plugins I like to install as a minimum:

  • Eclipse Color[sic] Theme

    This lets you change the colours to any of the preset themes packaged with it. It has some very nice dark themes; as the new supposed dark theme in Luna is awful. I'm partial to Obsidian myself. Once it's installed it can be accessed through Window > Preferences > General > Appearance > Color[sic] Theme.

  • FindBugs Eclipse Plugin

    FindBugs is a static code analysis tool that detects defects in your code. It has over 200 common bug patterns in its database. I make it a point to regularly run it against my projects. And running it couldn't be simpler; once installed simply right-click on your project in the Package Explorer and select Find Bugs > Find Bugs.

If you have any other tips, time saving tweaks, or you've spotted some major cock-up in the above list, tweet me @_deanwilliams