Book Image

OpenJDK Cookbook

Book Image

OpenJDK Cookbook

Overview of this book

Table of Contents (20 chapters)
OpenJDK Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Installing OpenJDK on Windows


Windows is the most commonly used OS in the world, and many developers are using it as their primary system. Despite its popularity, Windows doesn't have such strong support by the OpenJDK development community, and installation of the product is not as easy as in Linux. This recipe will cover the steps required to install OpenJDK on Windows.

This recipe provides an easy but decentralized way to install programs, although the most recent versions provide package repositories of their own. However, on Windows, the only official way to install an up-to-date OpenJDK is to build it from source.

Getting ready

To follow this recipe, we will need an installed Windows system. Windows 7 or Windows 8 will be best, because Windows XP is already officially discontinued by Microsoft.

How to do it...

There is an official build of OpenJDK on Windows, but it exists for referential purposes only. It is official and easy to install, but it doesn't have any security updates or improvements. However, there are unofficial builds, maintained by Alex Casco. We will try to install OpenJDK in both ways:

  1. We will start with an official reference build. To get it, we need to go to https://jdk7.java.net/java-se-7-ri/ and accept the license terms. Then, download and run the installer.

    Tip

    Though the OpenJDK source code is licensed by an open license, this official build is licensed by the Oracle Binary Code license and by GPLv2. If you want to keep your OpenJDK open source, please use one licensed by GPLv2.

  2. Unpack the downloaded file in a location you prefer. Let's name it C:/OpenJDK.

  3. Open the Windows command line by navigating to Start | Run, type cmd, and click on the Run button.

  4. Run the following command:

    C:\OpenJDK\bin\java.exe -version
    

    It will output the Java version information. The output should look like this:

    openjdk version 1.7.0
    OpenJDK Runtime Environment <build 1.7.0-b146>
    OpenJDK Client VM <build 21.0-b16, mixed mode>

Congratulations! We've just installed the OpenJDK official binary.

How it works…

The reference implementation is the only available official binary build of OpenJDK. But it lacks security and is used only for reference purposes. It is a simple archive that needs to be unpacked to use it.

To bypass this unpleasantness and give Windows users an opportunity to install OpenJDK as a binary without building it from source, one of the OpenJDK contributors established a completely unofficial but very useful OpenJDK build set for various platforms.

Moreover, this binary build, unlike the official one, is open source and licensed over GPL. So we can use it even in a completely open source environment without adding any proprietary pieces that will possibly get us in trouble.

Tip

You will find an installer for Mac in those unofficial builds as well.

There's more...

Though an official reference binary is outdated, there is an unofficial project that provides OpenJDK builds from sources that are up to date.

Now we will install OpenJDK 7 from unofficial builds:

  1. Go to https://github.com/alexkasko/openjdk-unofficial-builds.

  2. Select an appropriate build for Windows and download it.

  3. Unpack it and run install.exe.

  4. Click on the Run button when the preceding message appears.

  5. Carefully read and accept the license and then click on Next.

  6. Select the installation path in the next window. It will point to your home directory by default, so be careful—such an installation may be available to no one but yourself.

  7. If the target directory does not exist, let the installer create it.

  8. Check the red highlighted checkboxes in the preceding screenshot only if you want to set this JDK as default for all users in the system, not just for you. You may uncheck the fourth box if you don't need this JDK to be default at all.

  9. Then click on the Next button and wait until the installation is finished.

  10. Then click on the Next button for the last time.

  11. Then click on Done.

See also

Although the simplest way to install OpenJDK is to unpack binaries, manually or in an automatic fashion, there is no doubt that working with the source code will give us more flexibility at all possible levels.

To know more, read the following chapters:

  • Chapter 2, Building OpenJDK 6 up to Chapter 4, Building OpenJDK 8 to learn about building OpenJDK from source

  • Chapter 6, Building IcedTea with Other VM Implementations to build OpenJDK using other VMs

  • Chapter 13, Build Automation to work with future technologies, which will be unavailable in binary form for quite some time