Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
OpenJDK Cookbook

You're reading from   OpenJDK Cookbook Over 80 recipes to build and extend your very own version of Java platform using OpenJDK project

Arrow left icon
Product type Paperback
Published in Jan 2015
Last Updated in Feb 2025
Publisher
ISBN-13 9781849698405
Length 298 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
 Kobylyanskiy Kobylyanskiy
Author Profile Icon Kobylyanskiy
Kobylyanskiy
 Mironchenko Mironchenko
Author Profile Icon Mironchenko
Mironchenko
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Getting Started with OpenJDK FREE CHAPTER 2. Building OpenJDK 6 3. Building OpenJDK 7 4. Building OpenJDK 8 5. Building IcedTea 6. Building IcedTea with Other VM Implementations 7. Working with WebStart and the Browser Plugin 8. Hacking OpenJDK 9. Testing OpenJDK 10. Contributing to OpenJDK 11. Troubleshooting 12. Working with Future Technologies 13. Build Automation Index

Configuring OpenJDK on Linux

Linux configuration profiles differ from the Windows ones, because those systems are working with resources as well as with hardware in a slightly different fashion. Here, we will briefly explain those differences and a way to overcome them. Moreover, different Linux distributions, as always, have different ways to deal with the configuration. We will try to pass through the most noticeable ones.

Getting ready

To follow this recipe, you will need an OpenJDK instance installed on a Linux system. The deb, rpm, or ebuild distributions will suite us really well, although we will see a method for generic Linux configuration also.

Also, we will need the bash startup files to be installed properly.

Tip

In most Linux distributions, the generic way to configure anything that needs root access is not recommended, and the results of such an approach tend to vanish with each update. Usually, there are distribution-recommended how-to's where the problem solution is described.

How to do it...

First let's check whether your bash startup files are installed. The simplest possible way is to configure your OpenJDK using them. They are system-wide and easy to use, though there are drawbacks in their usage, such as update conflicts:

  1. Type the following line in your terminal:
    cat /etc/profile

    If the file exists and contains some kind of shell script, then your bash startup file's setup is probably correct. If not, please set it up by following your distribution instructions.

  2. Then add the /etc/profile.d/openjdk.sh file.
  3. In order to configure different things, write the following:
    To set JAVA_HOME
    JAVA_HOME=<youJDK installation directory>
    export JAVA_HOME
    
    To append JAVA_HOME to PATH
    pathappend $JAVA_HOME/bin PATH
    
    To adjust CLASSPATH directory
    AUTO_CLASSPATH_DIR=<classpath dir>
    pathprepend . CLASSPATH
    
    for dir in `find ${AUTO_CLASSPATH_DIR} -type d 2>/dev/null`; do
        pathappend $dir CLASSPATH
    done
    
    for jar in `find ${AUTO_CLASSPATH_DIR} -name "*.jar" 2>/dev/null`; do
        pathappend $jar CLASSPATH
    done
    
    export CLASSPATH

    Tip

    The CLASSPATH env variable should be avoided as much as possible. It is generally used by legacy Java applications mostly configured for JDK 1.2 and below. Use -classpath with java and javac commands instead.

The preceding code is quite simple—it just appends all JAR files to the classpath.

How it works…

This script is called during shell initialization, so whenever you perform shell initialization, these variables will be exported. The variables are thus system-wide, so be careful while playing with them, as they can cause your Java to fail permanently if you make some errors in this file.

There's more...

On Linux, you can see the directory structure of the installed OpenJDK using the tree command.

To do so, install the tree package (use your distribution's documentation if possible) and type:

tree -L 1 <path-to-openjdk> -lah

You will see something like the following:

/usr/lib/jvm/java-7-openjdk-amd64
├── [  22]  ASSEMBLY_EXCEPTION -> jre/ASSEMBLY_EXCEPTION
├── [4.0K]  bin
├── [  41]  docs -> ../../../share/doc/openjdk-7-jre-headless
├── [4.0K]  include
├── [4.0K]  jre
├── [4.0K]  lib
├── [4.0K]  man
├── [  20]  src.zip -> ../openjdk-7/src.zip
└── [  22]  THIRD_PARTY_README -> jre/THIRD_PARTY_README

This is the first-level directory structure in which:

  • ASSEMBLY_EXCEPTION is about licensing, and so is THIRD_PARTY_README.
  • The docs folder is for various OpenJDK documentation (changelog, copyrights, authors, and so on).
  • The include directory is to include paths (for JNI, for example).
  • The jre directory is where the Java Runtime is placed.
  • The lib directory is where various OpenJDK libraries are placed (such as Jigsaw or CORBA support; mainly, it consists of all OpenJDK code).
  • The man command is a manual pages entry for OpenJDK. It contains OpenJDK classes, javadocs, and other manual entries. It may be extremely useful in the highly improbable event of Internet connection loss.
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
OpenJDK Cookbook
You have been reading a chapter from
OpenJDK Cookbook
Published in: Jan 2015
Publisher:
ISBN-13: 9781849698405
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime
Modal Close icon
Modal Close icon