Distro independent Java development environment setup

Posted on June 1, 2016

Until few years back setting up Java development environment based on Sun/Oracle JDK was fairly a simple task. Since most of the linux distributions included Oracle/Sun JDK as part of their default package repository (here read as Canonical’s partner repository ;-)) it was as easy as installing any other core linux pacakge. But in recent times due to license restrictions Oracle JDK is not included in any of the linux distribution repositories by default. Setting up Java development environment manually from scratch on linux has become a tedious job (though still easier doing tha on Microsoft Windows). Nowadays I avoid doing it, given a chance to use a preconfigured virtual machines or chroot tar balls - created specifically for development/build requirements.

As for the intent of this post, it is to serve as a guide on best practices of setting up a Java development / build environment from scratch if such need arises in the future.

Prerequisites:

Oracle JDK version of your choice (in our case v1.7.079)

Apache Ant version of your choice (in our case 1.9.7) )which works with the JDK version chosen in step 1

Apache Maven version of your choice (in our case 3.0.5) which works with the JDK version chosen in step 1

Gradle version of your choice (in our case 2.13) which works with the JDK version chosen in step 1

Download tar ball archives of all the above packages. RPM package is available for Oracle JDK but it kills the “distro independent” part of this post.

Extract all the tar balls to a location of your convenience. If I have root or sudo access (which happens to be most of the time), I usually prefer /opt/tools/java.

After completing the extraction of tarballs to the /opt/tools/java direcory add the environment config scripts based on the below given template to /etc/profile.d directory of you linux file system.

At the end of the setup, your /etc/profile.d directory should look something like this