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-8.1
platform.
Note
A browser plugin and webstart implementation is provided by the
Icedtea project. To provide a complete implementation, you will
need to later install IcedTea-Web-1.7.
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.141 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
-
OpenJDK Root Package
Download:
http://hg.openjdk.java.net/jdk8u/jdk8u/archive/jdk8u141-b15.tar.bz2
Download MD5 sum: df3504e95d6e88924babb3821d4210a6
Download Size: 498 KB
-
In addition to the root package, the instructions below first
download seven subproject tarballs, whose total size is 63
MB.
-
Estimated disk space required: 3.5 GB (additional 529 MB for
tests)
-
Estimated build time: 4.3 SBU with 8 jobs in parallel (up to
120 SBU for tests, see below)
Additional Downloads
OpenJDK Dependencies
Required Dependencies
An existing binary (Java-1.8.0.141 or an earlier built version of
this package. The instructions below assume that you are using
Configuring the JAVA
environment), alsa-lib-1.1.4.1, cpio-2.12, Cups-2.2.4, UnZip-6.0, Which-2.21, Xorg Libraries, and
Zip-3.0
Recommended
Certificate Authority
Certificates, giflib-5.1.4, and Wget-1.19.1
Optional
Mercurial-4.3.1 and an X Window manager such
as twm-1.0.9 (for the tests)
User Notes: http://wiki.linuxfromscratch.org/blfs/wiki/openjdk
Installation of OpenJDK
Unlike other packages in BLFS, the OpenJDK source packages are distributed in
multiple tarballs. You need to first extract the source root from
jdk8u141-b15.tar.bz2
, change into the
extracted directory, then proceed with the following instructions:
cat > subprojects.md5 << EOF &&
4061c0f2dc553cf92847e4a39a03ea4e corba.tar.bz2
269a0fde90b9ab5ca19fa82bdb3d6485 hotspot.tar.bz2
a1dfcd15119dd10db6e91dc2019f14e7 jaxp.tar.bz2
16f904d990cb6a3c84ebb81bd6bea1e7 jaxws.tar.bz2
4fb652cdd6fee5f2873b00404e9a01f3 langtools.tar.bz2
c4a99c9c5293bb5c174366664843c8ce jdk.tar.bz2
c2f06cd8d6e90f3dcc57bec53f419afe nashorn.tar.bz2
EOF
for subproject in corba hotspot jaxp jaxws langtools jdk nashorn; do
wget -c http://hg.openjdk.java.net/jdk8u/jdk8u/${subproject}/archive/jdk8u141-b15.tar.bz2 \
-O ${subproject}.tar.bz2
done &&
md5sum -c subprojects.md5 &&
for subproject in corba hotspot jaxp jaxws langtools jdk nashorn; do
mkdir -pv ${subproject} &&
tar -xf ${subproject}.tar.bz2 --strip-components=1 -C ${subproject}
done
If you have downloaded the optional test harness, unpack it too:
tar -xf ../jtreg-4.2-b08-891.tar.gz
Note
Before proceeding, you should ensure that your environment
PATH
variable contains the location of
the Java compiler 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 recommend 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):
unset JAVA_HOME &&
sh ./configure \
--with-update-version=141 \
--with-build-number=b15 \
--with-milestone=BLFS \
--enable-unlimited-crypto \
--with-zlib=system \
--with-giflib=system \
--with-extra-cflags="-std=c++98 -Wno-error -fno-delete-null-pointer-checks -fno-lifetime-dse" \
--with-extra-cxxflags="-std=c++98 -fno-delete-null-pointer-checks -fno-lifetime-dse" &&
make DEBUG_BINARIES=true SCTP_WERROR= all &&
find build/*/images/j2sdk-image -iname \*.diz -delete
Note
Testing will involve the interplay of pairs of JVMs using the
networking interface, so networking must be started. If it isn't,
not only will these tests fail, but the test cleanup will leave
orphaned JVMs running. There will be many of them. Rebooting may
be the easiest recovery.
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:
if [ -n "$DISPLAY" ]; then
OLD_DISP=$DISPLAY
fi
export DISPLAY=:20
nohup Xvfb $DISPLAY \
-fbdir $(pwd) \
-pixdepths 8 16 24 32 > Xvfb.out 2>&1 &
echo $! > Xvfb.pid
echo Waiting for Xvfb to initialize; sleep 1
nohup twm -display $DISPLAY \
-f /dev/null > twm.out 2>&1 &
echo $! > twm.pid
echo Waiting for twm to initialize; sleep 1
xhost +
Then, it is necessary to modify some files:
echo -e "
jdk_all = :jdk_core \\
:jdk_svc \\
:jdk_beans \\
:jdk_imageio \\
:jdk_sound \\
:jdk_sctp \\
com/sun/awt \\
javax/accessibility \\
javax/print \\
sun/pisces \\
com/sun/java/swing" >> jdk/test/TEST.groups &&
sed -e 's/all:.*jck.*/all: jtreg/' \
-e '/^JTREG /s@\$(JT_PLATFORM)/@@' \
-i langtools/test/Makefile
Some variables have to be set:
JT_JAVA=$(type -p javac | sed 's@/bin.*@@') &&
JT_HOME=$(pwd)/jtreg &&
PRODUCT_HOME=$(echo $(pwd)/build/*/images/j2sdk-image)
The tests are run as follows:
LANG=C make -k -C test \
JT_HOME=${JT_HOME} \
JT_JAVA=${JT_JAVA} \
PRODUCT_HOME=${PRODUCT_HOME} all || true
LANG=C ${JT_HOME}/bin/jtreg -a -v:fail,error \
-dir:$(pwd)/hotspot/test \
-k:\!ignore \
-jdk:${PRODUCT_HOME} \
:jdk || true
Tests duration depends on various factors such as the network speed
and the number of concurrent VM, which is computed from the number
of cores and threads, and the amount of RAM installed. A maximum of
120 SBU has been observed, but it may be as “low” as 80 SBU.
The test results can be compared to these
results, although they usually are run on a newer version.
About 30 tests are known to fail, but the exact number depends on
various conditions, like whether the computer is connected to
network, or to a printer, and on the options given to configure
(--enable-unlimited-crypto
is known to trigger failures, but those come from the code in the
tests, not from the installation). Also, some tests may timeout if
the machine is under load.
Next some cleanup has to be done. The instructions below only stop
the frame buffer, but it has been reported that some java VM may be
left running after the tests, so it is necessary to check orphaned
processes:
kill -9 `cat twm.pid` &&
kill -9 `cat Xvfb.pid` &&
rm -f Xvfb.out twm.out &&
rm -f Xvfb.pid twm.pid &&
if [ -n "$OLD_DISP" ]; then
DISPLAY=$OLD_DISP
fi
Install the package with the following commands as the root
user:
cp -RT build/*/images/j2sdk-image /opt/OpenJDK-1.8.0.141 &&
chown -R root:root /opt/OpenJDK-1.8.0.141
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.141 /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.7:
tar -xf ../icedtea-web-1.7.tar.gz \
icedtea-web-1.7/javaws.png \
--strip-components=1
Now, as root
user:
mkdir -pv /usr/share/applications &&
cat > /usr/share/applications/openjdk-8-policytool.desktop << "EOF" &&
[Desktop Entry]
Name=OpenJDK Java Policy Tool
Name[pt_BR]=OpenJDK Java - Ferramenta de Pol�tica
Comment=OpenJDK Java Policy Tool
Comment[pt_BR]=OpenJDK Java - Ferramenta de Pol�tica
Exec=/opt/jdk/bin/policytool
Terminal=false
Type=Application
Icon=javaws
Categories=Settings;
EOF
install -v -Dm0644 javaws.png /usr/share/pixmaps/javaws.png
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
responsibility 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-extra-cflags=...
--with-extra-cxxflags=...
: Works around some defects in
the code brought to light by the GCC 6 more rigorous checking of
the C/C++ constructs. Remove those switches if compiling with GCC
5.
--with-jobs=N
: Allows setting 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 N=4, on a single processor, 4-core, virtual machine, with
4 GB of memory.
--with-cacerts-file=...
: Specifies
where to find a cacerts
file,
/etc/ssl/java/cacerts
on a BLFS
system. Otherwise, an empty one is created. You can use the
make-ca.sh --force
command to generate it, once you have installed the Java binaries.
make DEBUG_BINARIES=true SCTP_WERROR=
all: The build fails on 32 bit machines if
DEBUG_BINARIES is not set to true. Unsetting SCTP_WERROR is part of
the workarounds needed to use GCC 6. You may omit that part of the
command if using GCC 5.
find ... -iname '*.diz'
-delete: This command removes redundant files.