Java on Linux with multiple JDKs (Old, 2010)

Recently one of our linux servers at work crashed and died. I decided this time to skip the packages that come with the system and just come up with a more flexible way of compiling and running Java code.

May as well have multiple versions of Java. At the time I was coding in 1.5 so I needed a jdk5. But as I moved into the later testing phases of an application, I wanted to try some of the applications monitoring features in Java 6. So, to cover multiple bases, multiple JDKs.

First you want to download, I assume for all of us here, Java 5 and Java 6, jdk, sdk, the whole kit and caboodle!

Since the is all about options I like to:
1. Install the different versions of Java in /opt at the root level. You should be able to do this by typing ./java-file-you-downloaded.bin

2. Write a shell script that will set the Java version and location at run time. Just add, if using bash shell, export JAVA_HOME=/opt/jdkversion, and other path and classpath exports you need.

Using bash shell:

#! /bin/bash

export JAVA_HOME=/opt/jdk1.5.0_18
export PATH=$JAVA_HOME/bin:$PATH

3. Add to the shell script a call to your Java class.
java -classpath .:./moreDir:./anotherDir package.javaclass.class or no .class depending on your jdk

Now you can write shell scripts to compile, and run your code with different versions of Java just by creating a shell script!

Advertisements

Author: Michael Clayton

Technologist, Developer, Music Technology

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s