Beyond Linux® From Scratch - Version 7.7

Chapter 13. Programming

OpenJDK-1.8.0.31

Introduction to OpenJDK

OpenJDK is an open-source
implementation of Oracle's Java Standard Edition platform.
OpenJDK is useful for developing
Java programs, and provides a
complete runtime environment to run Java programs.

This package is known to build and work properly using an LFS-7.7
platform.

Note

A browser plugin and webstart implementation, as well as a
pulseaudio sound backend are provided by the Icedtea project. To
provide a complete implementation, you will need to later install
IcedTea-Web-1.5.2 and IcedTea-Sound-1.0.1.

OpenJDK is GPL'd code, with a special exception made for non-free
projects to use these classes in their proprietary products. In
similar fashion to the LGPL, which allows non-free programs to link
to libraries provided by free software, the GNU General Public
License, version 2, with the Classpath Exception allows third
party programs to use classes provided by free software without the
requirement that the third party software also be free. As with the
LGPL, any modifications made to the free software portions of a
third party application, must also be made freely available.

Note

The OpenJDK source includes a
very thorough, open source test suite using the JTreg test harness. The testing instructions
below allow to test the just built JDK for reasonable
compatibility with the proprietary Oracle JDK. However, in order
for an independent implementation to claim compatibility, it must
pass a proprietary JCK/TCK test
suite. No claims of compatibility, even partial compatibility,
may be made without passing an approved test suite.

Oracle does provide free community access, on a case by case
basis, to a closed toolkit to ensure 100% compatibility with its
proprietary JDK. Neither the binary version provided on the
Java-1.8.0.31 page nor the JVM built with the
instructions below have been tested against the
TCK. Any version that is built using the instructions given,
cannot claim to be compatible with the proprietary JDK, without
the user applying for, and completing the compatibility tests
themselves.

With that in mind, the binaries produced using this build method
are regularly tested against the TCK by the members listed on the
site above. In addition to the community license above, an
educational, non-commercial license for the TCK can be obtained
from here.

Source Package Information

The following files may be downladed from the OpenJDK mercurial
repository using the addresses
http://hg.openjdk.java.net/jdk8u/jdk8u/<component>/archive/jdk8u31-b13.tar.bz2,
where <component> is the name of the JVM component (corba,
hostspot, and so on), but that involves renaming the downloaded
files, and renaming the extracted directories. For convenience, the
BLFS editors have made the files available in an LFS website.

Recommended

Optional

Installation of OpenJDK

Unlike other packages in BLFS, the OpenJDK source packages are distributed in
multiple tar balls. You need to first extract the source root from
jdk8u31-b13.tar.bz2, change into the
extracted directory, then proceed with the following instructions:

Note

Before proceeding, you should ensure that your environment
PATH variable contains the location of
the Java compilers used for bootstrapping OpenJDK. This is the only requirement for
the environment. Modern Java installations do not need
JAVA_HOME and CLASSPATH is not used here. Furthermore, OpenJDK
developers recommand to unset JAVA_HOME.

The build system does not support the -j switch in MAKEFLAGS.

Configure and build the package with the following commands
(--with-milestone value can be modified to fit user preferences):

It seems that the test infrastructure of OpenJDK is a work in
progress, so that testing the newly built JVM involves several
steps. First, it is better to run the test suite in a frame buffer
on a different display, using Xvfb:

There are now two OpenJDK SDKs
installed in /opt. You should decide
on which one you would like to use as the default. Normally, you
would opt for the just installed OpenJDK. If so, do the following as the
root user:

ln -v -nsf OpenJDK-1.8.0.31 /opt/jdk

If desired, you may install a .desktop file corresponding to an
entry in a desktop menu for policytool. First, you need to
obtain an icon from IcedTea-Web-1.5.2:

The choice of pt_BR is just an example. You can add any translation
by adding lines corresponding to your locale, e.g. for fr_FR,
“Name[fr_FR]=” and
“Comment[fr_FR]=” with the
appropriate text as values.

Command Explanations

sh configure...: the
top level configure is a wrapper
around the autotools one. It is not executable and must be run
through sh.

--with-boot-jdk: This switch provides
the location of the temporary JDK.
It is normally not needed if java is found in the PATH.

--with-update-version:
Currently, the build system does not include the update number in
the version string. It has to be specified here.

--with-build-number: Again,
the build system does not include the build number in the version
string. It has to be specified here too.

--with-milestone: Used to
customize the version string.

--enable-unlimited-crypto:
Because of limitations on the usage of cryptography in some
countries, there is the possibility to limit the size of encryption
keys and the use of some algorithms in a policy file. This switch
allows to ship a policy file with no restriction. It is the
responsability of the user to ensure proper adherence to the law.

--with-zlib=system,
--with-giflib=system: Allows to use the system
libraries instead of the bundled ones.

--with-jobs=N: Allows to set the number
of jobs for make
equal to N. The default is the result of a calculation involving
the available memory and the number of processors. Note that even
if you specify N=1, some parallelization may be used during the
build. The SBU given above are with parallel jobs disabled, on a
single processor, single core, virtual machine.

--with-cacerts-file=...: Specifies
where to find a cacerts file.
Otherwise, an empty one is created. You can get it from an earlier
version of the package, or using the script below to generate one.

make DEBUG_BINARIES=true
all: The build fails if DEBUG_BINARIES is not set
to true.

find ... -iname '*.jar' -exec chmod
a+r {} \; and following line: Fix permission in
some library files, in order to allow all users to access them.

find ... -iname '*.diz'
-delete: This command and the the next one remove
redundant files.

Configuring
OpenJDK

Configuration Information

Normally, the JAVA environment has been configured after
installing the binary version, and can be used with the just
built package as well. Review Configuring the JAVA
environment in case you want to modify something.

To test if the man pages are correctly installed, issue
source /etc/profile
and man java to
display the respective man page.

Use the following procedure to install the cacerts or to generate a new one if Certificate Authority
Certificates have been updated. First, if it is not already
present, generate the mkcacerts script as the
root user:

Use the following commands to check if the cacerts file has been successfully installed:

cd /opt/jdk
bin/keytool -list -keystore jre/lib/security/cacerts

At the prompt "Enter keystore password:", press the "Enter" key
if there is no keystore password defined. If the cacerts file was installed correctly, you will
see a list of the certificates with related information for each
one. If not, you need to reinstall them.