OpenJDK is now an official Java 7 reference implementation, and is now one for Java 8 as well. This means that the most essential projects of the Java ecosystem are now open source. This also means that OpenJDK can be installed in various ways—from building from source to installing the binary package from the package manager, if any.
Sun's effort to release an open source JDK was the beginning of the project publicly stated in 2006, during the JavaOne conference. HotSpot was released under the GPLv2 license. The complete source code of the Java Class Library (JCL) was released in May 2007 under the GPL, except for several proprietary parts with GPL-incompatible licenses.
However, some proprietary parts (from 4 to 1 percent of the total code lines, depending on the update number) were required in OpenJDK in a separate proprietary bundle in the OpenJDK 7 b53 update in April 2009.
One may think that the initial installation and configuration are quite simple and do not need some sort of detailed explanation. In many ways, that's true; but there are some difficulties along the way.
We will start by distinguishing OpenJDK from Oracle JDK. The latter is based on the former, but not entirely. Each one has its own advantages and drawbacks. The primary OpenJDK advantage is the fact that it's open source while Oracle JDK is always recommended and is ready-to-use. Besides, OpenJDK 6 is the only maintainable Java 6 realization left, after the Java 6 discontinuation.
Then we will cover the installation process for Windows and possible issues with some Windows versions. After that, we will describe some typical profiles to configure an installed instance of OpenJDK for various needs, such as a server instance and developer instance.
Then we will go in to more complicated matters, such as installing OpenJDK on various Linux systems. There are at least two common ways to do it: the distribution-recommended way that depends on the distribution itself, and another way, which is common for all Linux systems.
Linux configuration is more or less the same as that of Windows, but there are some differences that need to be covered. The differences are, mainly, related to system philosophy, namely the way it's done and then what exactly is done.
Then we will proceed to OpenJDK internal structures—in an introductory way. We will consider OpenJDK projects that are already in use, and will learn how to use instruments that we will need later. Also, we will briefly look at OpenJDK groups and find out what they are doing and how they may influence OpenJDK's further evolution.
Last but not least, you will learn how to benefit from the Adopt OpenJDK program, which is also a part of the OpenJDK community. Adopt OpenJDK is an effort to improve OpenJDK usability readiness, test new language releases, and do whatever it needs to make OpenJDK more useful and welcoming among users as well as developers.
This chapter is written with an introductory purpose, and does not cover some details that are common to Oracle Java. However, it provides a necessary basis to work with.
We will use Java 7, as it is stable and the latest Java version available. All screenshots and processes are assuming that we use Java 7, if another is not explicitly mentioned.
If you already have OpenJDK built and installed as default and you are aware of the differences between OpenJDK and Oracle JDK, as well as of the existence of Adopt OpenJDK, you may skip this chapter entirely.
Though OpenJDK is an official reference implementation for the Java platform, certain Oracle-provided software are not open source. The most famous of them is the Java browser plugin, but there are a lot more differences than just that. This recipe will show you how to distinguish OpenJDK from Oracle JDK.
To follow this recipe, you will need an installed OpenJDK instance. It will be good if you have an Oracle JDK instance as well, to feel the difference. Also, we will assume that you have a Linux installation and an update-java-alternatives
command installed and ready to use. To know how to install OpenJDK on various systems, see the later recipes in this chapter. To know how to switch the system Java version, if you do not have update-alternatives
installed (for Fedora, Gentoo, and so on), visit the Configuring OpenJDK on Linux recipe or refer to your distribution documentation/forums.
Please take a look at the following procedures to know the difference between OpenJDK and Oracle JDK:
We will open a terminal and type the following command:
We will see a full list of installed Java implementations:
Let's set Oracle Java as default. We will run the following command with
root
access:Then we will go to https://www.java.com/en/download/installed.jsp?detect=jre and check our browser plugin version. We will see the activate link (following the name of the activating entity).
We can see from the result of our actions that the Java browser plugin has been installed.
Let's try to set OpenJDK as the default Java environment (the actual instance name may differ in your case):
Then we will go to our browser page and refresh it. It may be necessary to restart the browser so that the changes can take effect, as shown in the following screenshot:
We can see that the plugin is not from the JDK itself but from a project named IcedTea.
IcedTea is an open source project, whose goal is to replace proprietary parts of the Java ecosystem as much as possible. The plugin itself is from IcedTea-Web, an open source implementation of the Java Web Start and Java browser plugins.
In most distributions, the IcedTea
plugin is installed by default. But it is necessary to keep in mind that it's an open source plugin, and definitely not a referenced one. This means that its functionality might be slightly different from the Oracle plugin. It is also possible that some features may not work.
Oracle JDK still has some proprietary components, and the browser plugin is one example. All we need in this chapter is to see the difference between the work of OpenJDK and Oracle JDK components that are different.
Also, the huge difference between OpenJDK and Oracle JDK lies in the license. OpenJDK is open source, while Oracle JDK contains proprietary pieces, and thus it is licensed under the Oracle binary license. The fact that OpenJDK is open source provides a whole new range of benefits (and exciting discoveries) through the ability to study and modify its source code. It is also worth mentioning that more than 90 percent of Oracle JDK is based on OpenJDK source code. This means the OpenJDK quality is not compromised in any way. The browser plugin is not the only thing that is missed in OpenJDK compared to Oracle JDK.
In Chapter 5, Building IcedTea, there is a detailed explanation of how to build IcedTea from source.