Wednesday, October 21, 2009

Getting Started with Eclipse

For about the last month I have been learning Java. Due to outside requirements, I have been using the BlueJ IDE for development. However today I decided to give Eclipse a try.

I installed version 3.2.2 from the Ubuntu repos and loaded a project I had just completed in BlueJ. It was then that I was greeted with a few errors regarding my code. The first of which was:

    Scanner cannot be resolved to a type

The line of code in question was:

    private Scanner userInput = new Scanner(System.in);

Strange, I thought, since I had made no changes to the code and had just compiled and run this project in BlueJ.

I first checked the installed version of Java:

    $ java -version
    java version "1.6.0_0"
    OpenJDK Runtime Environment (IcedTea6 1.4.1) (6b14-1.4.1-0ubuntu11)
    OpenJDK Client VM (build 14.0-b08, mixed mode, sharing)


    $ javac -version
    javac 1.6.0_0

Ok, everything looked good there. I checked the compiler settings in Eclipse and changed the compiler from 5.0 compliant to 6.0 compliant. No joy.

After some more digging I concluded that the issue was probably that Eclipse was not using the proper JRE. Sure enough, Eclipse was using version 1.5 at /usr/lib/jvm/java-1.5.0-gcj-4.3-1.5.0.0. I added another JRE entry pointing to /usr/lib/jvm/java-6-openjdk (which is what my BlueJ installation was already using) and voila! No more errors.

I guess I should look into cleaning up the multiple JRE's I have installed on this machine.

But first, back to exploring Eclipse!

No comments:

Post a Comment