Showing posts with label OpenJDK. Show all posts
Showing posts with label OpenJDK. Show all posts

Saturday, July 7, 2012

OpenJDK on Linux Mint 13 - Part 2


Part 2: Installing & Configuring OpenJDK via GUI

This article outlines an alternative method of installing and configuring OpenJDK versions 6 and 7 using GUI programs instead of executing commands in a terminal. Choosing and installing the OpenJDK's will be carried out using the Synaptic Package Manager and switching between versions of OpenJDK will be done using the 'galternatives' utility. Note that the Synaptic Package Manager has been already installed as part of the standard packages during installation of Linux Mint 13 and does not have to be re-installed. The 'galternatives' utility, however, has to be installed. So, start up the Synaptic Package Manager (using Menu > Administration > Synaptic Package Manager) and type 'galternatives' into the search box as shown in the figure below and press Enter.



Click on the box besides the package name to select it and then press the Apply button. Press the Enter key at the confirmation screen that appears next. An installation status will then appear - close it when the installation is complete.

Next you need to choose and install the openjdk-6-jdk, openjdk-6-doc, openjdk-6-demo, openjdk-6-dbg, openjdk-7-jdk, openjdk-7-doc, openjdk-7-demo, and openjdk-7-dbg packages. Type 'openjdk' into the Synaptic's search box and press Enter. On the resulting screen as shown below, select all the packages mentioned previously. Then press the Apply button, followed by the Enter key to confirm the installation. Wait for the packages to be downloaded and installed - then close the installation status dialog box when completed.



Next you need to verify that both versions of OpenJDK has been installed using the 'galternatives' utility. To run the 'galternatives' utility, press Alt+F2 and the type galternatives into the box that appears. On the confirmation dialog box that appears next, type in the root password (galternatives requires root privilages) and press Enter. The galternatives utility will start as shown in the figure below.



Navigate to the 'Java' entry on the left-side and you will see a screen similiar to the one shown above. Note that the 64-bit version is shown in the figure - the 32-bit version will display 'i386' instead of 'amd64'. The version 6 of OpenJDK is the selected one at the moment. You can change the version to OpenJDK version 7 by clicking on the radio button under the 'Choice' column. Note that if you decide to use version 7, make sure that all the entries related to Java (normally preceeded by the letter 'j') on the left-hand side (for example; jar, jarsigner, javac ... etc) are selected and changed to version 7. The 'galternatives' utility makes switching between different OpenJDK versions easier by doing it in one place rather than having to run sudo update-alternatives --config xxxx (where xxxx is the item to be changed) for each and every Java related items on a terminal. Try switching between versions but remember to reset to OpenJDK version 6 once you have completed your tests.

Friday, July 6, 2012

OpenJDK on Linux Mint 13 - 32 & 64 Bits

Part 1: Installing & Configuring OpenJDK via the Command Line

(NOTE: All the commands shown in this article are typed in a terminal started using either the menu or the Alt-Ctl-T shortcut.)

On a newly installed (and updated) Linux Mint 13, the command:

  java -version

would display the following:

  java version "1.6.0_24"
  OpenJDK Runtime Environment (IcedTea6 1.11.1)
    (6b24-1.11.1-4ubuntu3)
  OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

This would indicate that the OpenJDK JRE version 6 has been installed as part of the 'standard' installation. Just to make sure that this is the only Java installed, the command:

  sudo update-alternatives --config java

will display:

  There is only one alternative in link group java: 
    /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
  Nothing to configure.


Since we are interested in developing software using Java, we need to install the JDK version of OpenJDK. To do this type the command:

  sudo apt-get install openjdk-6-jdk

Press Enter when prompted "Do you want to continue [Y/n]?" and the JDK will be installed. Now you have both the JRE and the JDK version 6 installed. To make Java programming easier, it is also recommended that the OpenJDK documentation be installed. This can be done by the command:

  sudo apt-get install openjdk-6-doc

If you are interested, you can also install the OpenJDK demo programs by executing:

  sudo apt-get install openjdk-6-demo

A debugger is also available and can be installed by executing:

  sudo apt-get install openjdk-6-dbg

A quick check using the Synaptic Package Manager (using Menu > Administration > Synaptic Package Manager) shows that the OpenJDK version 7 is also available. Can this be installed alongside the version 6 and can the user select which version to use? The answer is Yes to both. This can be achieved by the command:

  sudo apt-get install openjdk-7-jdk openjdk-7-doc openjdk-7-demo openjdk-7-dbg

To select which Java to use, run the command:

  sudo update-alternatives --config java

The output is as shown below:



Press the Enter key to keep using OpenJDK version 6 or press '2' to switch to and use OpenJDK version 7. To test the switch, press '2' at the prompt shown above and then run the command:

  java -version

should display:

  java version "1.7.0_03"
  OpenJDK Runtime Environment (IcedTea7 2.1.1pre)
    (7~u3-2.1.1~pre1-1ubuntu3)
  OpenJDK 64-Bit Server VM (build 22.0-b10, mixed mode)

Now switch back to using version 6 by executing:

  sudo update-alternatives --config java

and type '0' or '1' to switch back. You can verify it by running:

  java -version

and you should see:
 
  java version "1.6.0_24"
  OpenJDK Runtime Environment (IcedTea6 1.11.1)
    (6b24-1.11.1-4ubuntu3)
  OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

To make switching between different versions of OpenJDK easier, I recommend that the package 'galternatives' be installed. This is a GUI version of update-alternatives and lets you switch versions visually. To install, run:

  sudo apt-get install galternatives

and press Enter at the prompt. When installed, you can run the utility by executing:

  sudo galternatives

A dialog box (shown below) will appear:



Navigate to the 'Java' entry on the left-side and you will see a screen similiar to the one shown above. The version 6 of OpenJDK is the selected one at the moment. You can change the version to OpenJDK version 7 by clicking on the radio button under the 'Choice' column. Note that if you decide to use version 7, make sure that all the entries related to Java (normally preceeded by the letter 'j') on the left-hand side (for example; jar, jarsigner, javac ... etc) are selected and changed to version 7. The 'galternatives' utility makes switching between different OpenJDK versions easier by doing it in one place rather than having to run sudo update-alternatives --config xxxx (where xxxx is the item to be changed) for each and every Java related items. Once the choices have been made, close the dialog box and you are done switching. Verify by running the commands 'java -version', 'javac -version', etc in a terminal.

For those wondering about the difference between OpenJDK 6 and OpenJDK 7, the following links should clarify the matter:

https://blogs.oracle.com/darcy/entry/openjdk_6_genealogy

and

http://www.infoq.com/news/2007/09/openjdk6

My recommendation is that OpenJDK 6 be used at the moment - that is, if the user decides to use OpenJDK as the Java platform for developing applications.

Java Flavors on Linux

While composing a new blog on Android programming on Linux, I discovered an interesting fact - there are 6 'flavors' of Java currently available for the latest Linux distributions. To make things simpler, I decided to use the latest versions of Ubuntu and Mint - versions 12.04 LTS (Precise Pangolin) and 13 (Maya) respectively and use these 'flavors' of Java on them. Both the 32-bit and 64-bit versions will be covered in the blog. Why these two? The answer is that these two are considered to be the most popular distributions - at least according to the latest page hit ranking on Distrowatch.

The first portion on my forthcoming blogs is installing and configuring the 6 'flavors' of Java on Linux Mint 13 (32 and 64 bits). The first part is installing and configuring OpenJDK versions 6 and 7 on the same computer plus the ability to switch between the 2 versions of OpenJDK. Two methods will be outlined - using the command line as well as using GUI tools exclusively.

Readers may wonder why both versions are installed. Why not just stick with one? The answer can be summed up in one word - flexibility. With both versions installed on the same computer, it is now possible to test a program on both version (not at the same time, of course) to see if they are error-free. You can also write a program exclusively for one version without having to worry about conflicts and then switch to another version to write another program for that version exclusively. Having the ability to switch between versions makes program development more flexible.

Stay tuned for the first part...