close up photo of programming of codes

Configure Eclipse IDE to work with Java 8 32-bit custom libraries on Linux Mint 20.3

Introduction

I recently found an excellent Java course published by Stanford University titled “CS106A – Programming Methodology”. The professor, Mehran Sahami, is a very engaging instructor and I like his video lectures. CS106A is published for free by Stanford Engineering Everywhere at https://see.stanford.edu/Course/CS106A (Thank you, Stanford!). I set a challenge for myself to create a lab environment that I could use to follow this programming course exactly as it was taught; with the same style, syntax, strings and other such details.

The lab consists of the following main components:

  • Operating System: Linux Mint 20.3 running in a virtual machine
  • Virtual Machine: Oracle VM VirtualBox
  • Software Development Platform: Java 8 32-bit
  • IDE Software: Eclipse IDE 2022-03 for Linux

The challenges I faced were to make the above components work with the Stanford’s CS106A course. My plan was to run a modern version of the Eclipse IDE on Linux Mint 20 in a virtual machine while making this setup work so it would match the course content developed 15 years ago, in 2007. The Eclipse IDE used in the class reflects that time period, being compatible with Windows Vista and XP. So does the version of Java used in those days; Java 6 32-bit, with custom Java libraries developed for the course.

The two main challenges I had were to 1) get a 32-bit version of Java 8 working on the 64-bit version of Linux I wanted to use, and to 2) configure Eclipse to work with the version of Java I was installing as well as the custom libraries provided by Stanford.

Fast forward to the writing of this post. I figured out how to create the lab environment I wanted and what follows is a tutorial on how to create a modernized development environment to follow along with CS106A.

Prerequisites

I am not going to cover the installation and set up of a virtual machine. I am going to assume that you know how to install and configure virtual machines using VirtualBox. There are plenty of tutorials online showing how to install Linux on VirtualBox, so I am not going to cover that here.

I am going to explain the steps to installing Java and Eclipse on my chosen version of Linux and how to configure those componentes to work with CS106A. If you want to follow along with the exact VM I am using, install Linux Mint 20.3 on a VirtualBox virtual machine, with the latest updates and Guest Additions installed.

Java

Challenge #1 is to configure Linux Mint 20.3 with Java 8 32-bit. Linux Mint 20.3 is 64-bit and comes with an existing open-source version of Java installed. My installation comes with OpenJDK version 11.0.15, so in other words an open-source variety of Java 11. I want to change this configuration to work with Oracle JDK 1.8 (Java 8).

STEP 1: Download 32-bit Oracle Java SE Development Kit 8.

At the time of writing this article, the version I’m using is JDK 8u321 obtained from https://www.oracle.com/java/technologies/downloads/.

Download the tarball from the link provided. I downloaded the file named “jdk-8u321-linux-i586.tar.gz”. Feel free to download the latest version, though I have not tested to see if it will work with this tutorial.

Step 2: Unzip the downloaded tarball.

tar -zxvf jdk8u321-linux-i586.tar.gz

Step 3: Create a folder named java in /usr/lib. You need root permission to do this, and make sure you are in the /usr/lib directory.

sudo mkdir java

Step 4: Move the extracted folder to /usr/lib/java/.

sudo mv jdk1.8.0_321 /usr/lib/java

Step 5: Run the following scripts in the terminal:


sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/java/jdk1.8.0_321/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/jdk1.8.0_321/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/java/jdk1.8.0_321/bin/javaws" 1

sudo update-alternatives --set java /usr/lib/java/jdk1.8.0_271/bin/java
sudo update-alternatives --set javac /usr/lib/java/jdk1.8.0_271/bin/javac


Step 6: Update JAVA_HOME in your ~/.bashrc file.

To open bashrc, run:

sudo gedit ~/.bashrc

Paste the following text under “enable programmable completion…” in the bashrc file:

#JAVA HOME directory setup
export JAVA_HOME=/usr/lib/java/jdk1.8.0_321
export PATH=”$PATH:$JAVA_HOME/bin”

Save and exit the bashrc file.

Step 7: Verify the previous scripts by running the following in the terminal:
update-alternatives –list java
update-alternatives –list javac

Step 8: If you recall from earlier, we installed a 64-bit edition of Linux Mint. We need to add 32-bit architecture to make this version of Java work. Run the following commands in the terminal:

sudo dpkg –add-architecture i386
sudo apt-get update
sudo apt-get install libc6-i386

Step 9: To verify Linux Mint is now running with the Java version we want, run the following command:

java -version

As you can see, we are running 1.8.0_321, which is what we want. We have now successfully installed 32-bit Java 8 on our machine.

Eclipse

The next step is to install Eclipse and get it configured correctly. Since I have done this lab setup before, I already know there are a few missing libraries that need to be installed for the software to work correctly.

Step 1: Go ahead and run the following commands in the terminal to install the needed libraries:

apt install libxext6:i386
apt install libxrender1:i386
apt install libxtst6:i386
apt install libxi6:i386

Step 2: Download Eclipse for Linux. I am using Eclipse IDE for Java Developers, Linux x86_64 found at https://www.eclipse.org/downloads/packages/.


Step 3: Extract the tarball for Eclipse.

tar -zxvf eclipse-java-2022-03-R-linux-gtk-x86_64.tar.gz

Step 4: To launch Eclipse, type the following commands in terminal (in Downloads directory):

cd eclipse

./eclipse

Step 5: You will be presented with a window asking you to select a directory as your workspace. I left the suggested directory path as default and clicked “launch”.

Step 6: From the menu options, select Window>Preferences. Navigate to Java>Installed JREs.

Click “Add”, click “Next” with the “Standard VM” option selected, then click “Directory”.

Navigate to /lib/java/, select the folder named “jdk1.8.0_321”, then click “Open”.

If you did it this correctly, you will see the following as shown in the image. Click Finish.

Step 7: In the Preferences window, deselect “jre” and place a checkmark next to “jdk1.8.0_321”.

Step 8: Navigate to Java>Compiler on the left side in the Preferences window. Set “Compiler compliance level” to 1.8. Click “Apply and Close”.

Step 9: Next, we will test that our work configuring Java and Eclipse has paid off by creating a small Hello World program. We will have to add an external JAR during this process, which you can go ahead and download at https://cs.stanford.edu/people/eroberts/jtf/acm.jar.

Step 10: In Eclipse, click File>New>Java Project. We will name our project HelloWorld for simplicity. Make sure under JRE options that “Use default JRE ‘jdk1.8.0_321’ and workspace compiler preferences” is selected. Click Finish.

You should see the new project HelloWorld under Package Explorer on the left side of Eclipse.

Step 11: Right-click HelloWorld, click Properties, then in the Properties window navigate to Java Build Path>Libraries.

You should already see jdk1.8.0_321, and we need to add the external acm.jar file we downloaded a moment ago. To do so, click “Add External JARs”, then add acm.jar from your download folder. You should see two items in the build path. Click “Apply and Close”.

Step 12: We will now create a new Java Class where we will write our program. To do so, right click HelloWorld in Package Explorer, then click New>Class. Enter HelloWorld in the Name field, then click Finish.

Step 13: A new class named HelloWorld.java will be created. Delete any text populated in the program and add the following:

Step 14: Once you have the program created, click on the green play button. If all goes well you will launch a new applet confirming that you have successfully installed and configured the development lab.

Leave a Comment

Your email address will not be published. Required fields are marked *