Java is different from most of the packages in LFS and BLFS. It is a programming language that works with files of bytecode to obtain instructions and executes them in a Java Virtual Machine (JVM). An introductory java program looks like:
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello, World");
}
}
This program is saved as HelloWorld.java. The file name, HelloWorld, must match the class name.
It is then converted into byte code with javac HelloWorld.java. The output
file is HelloWorld.class. The program
is executed with java
HelloWorld. This creates a JVM and runs the code.
The 'class' extension must not be specified.
Several class files can be combined into one file with the jar command. This is similar to the standard tar command. For instance, the command jar cf myjar.jar *.class will combine all class files in a directory into one jar file. These act as library files.
The JVM can search for and use classes in jar files automatically.
It uses the CLASSPATH environment
variable to search for jar files. This is a standard list of
colon-separated directory names similar to the PATH environment variable.
Creating a JVM from source requires a set of circular dependencies. The first thing that's needed is a set of programs called a Java Development Kit (JDK). This set of programs includes java, javac, jar, and several others. It also includes several base jar files.
To start, we set up a binary installation of the JDK created by the
BLFS editors. It is installed in the /opt directory to allow for multiple
installations, including a source based version.
Development versions of BLFS may not build or run some packages properly if LFS or dependencies have been updated since the most recent stable versions of the books.
Binary download (x86_64): https://anduin.linuxfromscratch.org/BLFS/OpenJDK/OpenJDK-25.0.5.0.3/OpenJDK-25.0.5.0.3+1-x86_64-bin.tar.xz
Download MD5 sum: c65199251a4da20bc5cff7e26bd9691e
Download size (binary): 186 MB
Estimated disk space required: 388 MB
Starting with OpenJDK-25, the support for the 32-bit server and client JVM has been removed. OpenJDK can still be built for the “zero” JVM variant, which does not use any assembly code and has performance issues. The BLFS developers have therefore decided not to provide the 32-bit binary build anymore. If 32-bit is needed, you should use OpenJDK-21, which is well maintained. A java binary can be found at https://anduin.linuxfromscratch.org/BLFS/OpenJDK/ and used to build the most recent version of OpenJDK-21. This binary may be out of date and suffer vulnerabilities, but is good enough to build from source.
alsa-lib-1.2.16.1, Cups-2.4.20, giflib-6.1.3, Little CMS-2.20, and Xorg Libraries
Install the binary OpenJDK with
the following commands as the root
user:
install -vdm755 /opt/OpenJDK-25.0.5.0.3-bin && mv -v * /opt/OpenJDK-25.0.5.0.3-bin && chown -R root:root /opt/OpenJDK-25.0.5.0.3-bin
The binary version is now installed. You may create a symlink to
that version by issuing, as the root user:
ln -sfn OpenJDK-25.0.5.0.3-bin /opt/jdk
You may now proceed to Configuring the Java environment, where the instructions assume that the above link exists.