Recently, Docker (and its related technologies) has become more popular. This has encouraged businesses to find more ways to utilise it in their IT environments. One of the interesting developments has been the request to create ready-made development environments, so that new members to the IT team need not worry about parameters or software dependencies.
There are many tools available to create virtual machines (or containers) from code (or “automatically”). We’ve been using Vagrant because it has lots of well-supported “base boxes” available. Boxes are foundational virtual machine images upon which you can build various customisations. In our scenario we want to install the Eclipse IDE and set up a functional development workspace.
Preparation
Before we can begin, there are a few requirements:
- Terminal
Linux / Unix systems will already have a terminal (command-line interface) available.
Windows users may need to install a similar tool (such as Git Bash). - Virtual Machine
Vagrant works in combination with many different virtualisation software. We often use VirtualBox because it’s free, but it’s likely that Vagrant also works with your personal preference. - Vagrant
Vagrant is a command-line tool, but is not installed by default on most systems. You can find the latest versions at vagrantup.com. - Vagrant Plugins
There are a lot of plugins that make Vagrant development a little easier. Here are two we need:- vagrant-reload
is useful for restarting the box during customisation stepsvagrant plugin install vagrant-reload
- vagrant-vbguest
is useful in combination with VirtualBox for installing guest additionsvagrant plugin install vagrant-vbguest
- vagrant-reload
- Collaboration / Versioning
You probably want to share and maintain your final vagrantfile result. This can become a lot easier when using a collaboration or versioning tool. Git is a popular choice which has many online hosting options (or can be run entirely locally). - Text Editor
Any text editor should be able to open a vagrant setup file, but you may find it easier with syntax highlighting (for Ruby, although no Ruby experience or knowledge is necessary).
Vagrantfile
vagrant --init
This terminal command will create a basic vagrant setup file (called vagrantfile). You should not change this filename, as vagrant will always search for the file named “vagrantfile”. Opening it in a text editor will allow us to start setting up our development environment.
# Eclipse IDE Example
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.provider "virtualbox" do |vb|
vb.name = "EclipseExample"
vb.memory = "8192"
vb.cpus = "4"
vb.gui = true
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
vb.customize ["modifyvm", :id, "--draganddrop", "bidirectional"]
end
We start out with a very basic virtual machine:
- Pick a base “box”
- CentOS 7
A simple Linux installation without many features; it is well maintained by the official CentOS community.
- CentOS 7
- VirtualBox-specific customisations
- The virtual machine name which will appear in VirtualBox
- The amount of RAM and processor assigned to the virtual machine
- Don’t start the virtual machine in the background; use the GUI
- Share a folder so that we can move files from the local machine to the virtual machine (such as Eclipse IDE config files)
We’ve put our Java project code in here to keep things simple, but you may want to use Git or another tool to import your most recent project code to load into Eclipse.- . = the folder in which the vagrantfile is. The entire contents will be shared with VirtualBox
- /vagrant = the location in the virtual machine where you can access the shared folder
- Make life easier by enabling drag-and-drop functionality in VirtualBox
If you launch this vagrantfile, you should see CentOS start up in VirtualBox! Now we need to add our customisations; Vagrant allows us to do this by executing shell scripts. For example, this script sets up the virtual machine’s clock and keyboard settings:
config.vm.provision "Set System Locale", privileged: true, type: "shell", inline: "timedatectl set-timezone Europe/Brussels && localectl set-x11-keymap us pc105s intl"
You can find more information about setting your keyboard preference here.

Eclipse
That means we’re almost ready to install Eclipse. Before that, though, we need to install a graphical desktop; the CentOS installation only comes with a command-line interface! Since Eclipse is a graphical IDE, we’ll need a graphical desktop:
config.vm.provision "Install Desktop GUI", privileged: true, type: "shell", inline: "yum groupinstall -y 'GNOME Desktop' 'Graphical Administration Tools' && systemctl set-default graphical.target"
The above script will install the standard GNOME graphical desktop, and then tells CentOS to use the graphical interface by default when the system is restarted (as opposed to launching the command-line interface).
Now we can download and install Eclipse IDE:
config.vm.provision "Install Eclipse 2018-09", privileged: false, type: "shell", inline: "wget --quiet http://eclipse.bluemix.net/packages/2018-09/data/eclipse-jee-2018-09-linux-gtk-x86_64.tar.gz && sudo tar xfz eclipse-jee-2018-09-linux-gtk-x86_64.tar.gz -C /opt"
We’re downloading the 2018-09 Eclipse Java EE IDE version for Linux using the official Bluemix download. Eclipse is then installed into Linux’ recommended folder for applications.
The vagrant-reload plugin can now be used to automatically restart the virtual machine (which will switch to the graphical user interface):
config.vm.provision :reload
If you launch the Vagrant machine now, you will be able to log in and launch Eclipse from the file explorer, but it may be handy to include a shortcut in the applications menu:
config.vm.provision "Eclipse Shortcut", privileged: true, type: "shell", inline: "sudo printf '[Desktop Entry]\nVersion=2018-09\nName=Eclipse\nComment=Eclipse Java Enterprise Edition\nExec=/opt/eclipse/eclipse\nIcon=/opt/eclipse/icon.xpm\nTerminal=false\nType=Application\nCategories=Utility;Application;Development;' > /opt/eclipse/Eclipse.desktop && cp /opt/eclipse/Eclipse.desktop /usr/share/applications/Eclipse.desktop"

Workspace
The easiest way to set up the Eclipse IDE workspace is to copy an existing workspace; launch the vagrantfile now and manually configure your personal Eclipse IDE workspace.
- Use the default suggested workspace
That means you don’t need to remember where the workspace was configured. - Customise your Eclipse settings
We’ve configured a custom Maven Install “run” command that ignores test results. - Import your project
In our example, the project is included in the shared folder. A more sensible approach would be to use Git to import the project in a prior vagrant customisation script (which is not covered here).
Once these steps are completed, you can copy the entire Eclipse workspace into the shared folder (/vagrant). We created the folder “/vagrant/eclipse-workspace”. Since the folder is shared, you can find the new folder on your host machine even after stopping or deleting your virtual machine. Now we can re-use the workspace for all future launches:
config.vm.provision "Setup Eclipse Workspace", privileged: false, type: "shell", inline: "mkdir -p /home/vagrant/eclipse-workspace && cp -r /vagrant/eclipse-workspace/. /home/vagrant/eclipse-workspace/"
Now if you launch the vagrantfile, you can start Eclipse IDE from the applications menu, and if you accept the default workspace, the project will be loaded automatically!
Final Steps
However, there are still some important aspects to take into account:
- If your project requires extra tools (such as Maven), you will need to install them in a customisation script:
config.vm.provision "Install Git, Maven", privileged: true, type: "shell", inline: "yum install -y git maven"
- For Maven projects, Eclipse finds .project and .classpath files important. These are often excluded from Git repositories, so you might need to generate a valid version for the project:
config.vm.provision "Eclipse Project Files", privileged: false, type: "shell", inline: "cd /{project} && mvn eclipse:eclipse"

Don’t forget to replace {project} with the path to your actual project folder. Project and classpath settings should be automatically configured using your Maven .pom settings.
- Lastly, to make it easier to copy, here’s our completed vagrantfile (you’ll still need to add your project files and Eclipse workspace files):
# Eclipse Example
# https://docs.vagrantup.com
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
# VirtualBox-Specific Setup
config.vm.provider "virtualbox" do |vb|
vb.name = "Eclipse Example"
vb.memory = "8192"
vb.cpus = "4"
vb.gui = true
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
vb.customize ["modifyvm", :id, "--draganddrop", "bidirectional"]
end
config.vm.provision "Set System Locale", privileged: true, type: "shell", inline: "timedatectl set-timezone Europe/Brussels && localectl set-x11-keymap us pc105s intl"
config.vm.provision "Install Desktop GUI", privileged: true, type: "shell", inline: "echo 'installing desktop ...' && yum groupinstall -y 'GNOME Desktop' 'Graphical Administration Tools' && systemctl set-default graphical.target && echo 'desktop installed!'"
# Our project uses Maven
config.vm.provision "Install Maven", privileged: true, type: "shell", inline: "yum install -y maven"
config.vm.provision "Install Eclipse 2018-09", privileged: false, type: "shell", inline: "wget --quiet http://eclipse.bluemix.net/packages/2018-09/data/eclipse-jee-2018-09-linux-gtk-x86_64.tar.gz && sudo tar xfz eclipse-jee-2018-09-linux-gtk-x86_64.tar.gz -C /opt"
config.vm.provision "Configure Eclipse", privileged: false, type: "shell", inline: "mkdir -p /home/vagrant/eclipse-workspace && cp -r /vagrant/eclipse-workspace/. /home/vagrant/eclipse-workspace/ && cd /{project} && mvn eclipse:eclipse"
config.vm.provision "Eclipse Shortcut", privileged: true, type: "shell", inline: "printf '[Desktop Entry]\nVersion=2018-09\nName=Eclipse\nComment=Eclipse Java Enterprise Edition\nExec=/opt/eclipse/eclipse\nIcon=/opt/eclipse/icon.xpm\nTerminal=false\nType=Application\nCategories=Utility;Application;Development;' > /opt/eclipse/Eclipse.desktop && cp /opt/eclipse/Eclipse.desktop /usr/share/applications/Eclipse.desktop"
# Restart into graphical desktop
config.vm.provision :reload
end