Eclipse IDE Automated Setup in Vagrant

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 steps
    • vagrant-vbguest
      is useful in combination with VirtualBox for installing guest additions
  • 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

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.

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.
  • 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:

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:

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:

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):

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:

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:

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:
  • 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:
  • 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):
blogger

blogger

Curious to know more about this topic?

Working at i8c

i8c is a system integrator that strives for an informal atmosphere between its employees, who have an average age of approx 30 years old. We invest a lot of effort in the professional development of each individual, through a direct connection between the consultants and the management (no multiple layers of middle management). We are based in Kontich, near Antwerp, but our customers are mainly located in the triangle Ghent-Antwerp-Brussels and belong to the top 500 companies in Belgium (Securex, Electrabel, UCB, etc…).

Quality Assurance

i8c is committed to delivering quality services and providing customer satisfaction. That’s why we invested in the introduction of a Quality Management System, which resulted in our ISO9001:2000 certification. This guarantees that we will meet your expectations, as a reliable, efficient and mature partner for your SOA & integration projects.

i8c - ISO9001-2015

Also worth reading

AWS AppFlow: Streamlining SaaS Integrations with AWS Services

In today’s digital world, organizations are constantly looking for ways to streamline their workflows and improve their data management processes. One of the key challenges that organizations face is integrating their various software as a service (SaaS) applications with their data management systems. This is

Read More »

Apigee Scope Validation using OpenAPI Specification

In API security and management, we often use a lot of different security mechanisms to protect the requested resource behind the API Gateway. One of these mechanisms is the validation of scopes to authorize a client on a specific sub-resource of the API. Most of

Read More »