0

I just started to learn Java using Thinking in Java book, and have some troubles using ant.

I'm using Ubuntu 12.04, and have openjdk 7 java installed. I also setup the CLASSPATH to be the code folder

When I run ant in code folder, this is the output:

Exception in thread "main" java.lang.RuntimeException: JDK 1.4.1 or higher is required to run the examples in this book. [CheckVersion] at com.bruceeckel.tools.CheckVersion.main(Unknown Source) 

However when I run java -version, this is the output:

java version "1.6.0_27" OpenJDK Runtime Environment (IcedTea6 1.12.5) (6b27-1.12.5-0ubuntu0.12.04.1) OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode) 

How to setup ant and classpath correctly?

P/S: Thanks everyone for the help!!! I figured out why it fails to check the version. The testing condition is "if(minor < '4' || point < '1')" in CheckVersion.java. Yet my version is 1.6.024, eventhough 6>4 but 0<1 that's why it failed. I guess we need to rewrite the testing condition!

2
  • 1
    Do you have another JDK installed somewhere? Try running, "ant -diagnostics" it will dump out all the environment, etc. Commented Jun 30, 2013 at 23:58
  • I think I currently have two JVM: update-java-alternatives -l java-1.6.0-openjdk-amd64 1061 /usr/lib/jvm/java-1.6.0-openjdk-amd64 java-1.7.0-openjdk-amd64 1051 /usr/lib/jvm/java-1.7.0-openjdk-amd64 Commented Jul 1, 2013 at 0:16

1 Answer 1

4

Try setting your JAVA_HOME environment variable to the install directory of your 1.6 JDK.

When you type "java -version", the command shell is using the first java executable it finds in your PATH. Ant probably looks for the java executable in the "bin" sub-directory of your JAVA_HOME directory.


To find the location of your java executable, type the following:

which java 

and let's say you got the following output:

/usr/local/java1.6/bin/java 

You would then set your JAVA_HOME variable to /usr/local/java1.6. Assuming a Bourne or Bash shell, the syntax for that would be

export JAVA_HOME=/usr/local/java1.6 
Sign up to request clarification or add additional context in comments.

7 Comments

My JAVA_HOME is $JAVA_HOME bash: /usr/lib/jvm/java-1.7.0-openjdk-amd64: Is a directory
Can you verify that there the file "/usr/lib/jvm/java-1.7.0-openjdk-amd64/bin/java" exists and has execute permission?
Given that there is definitely a 1.6 java installed (as proved when you entered "java -version"), please try setting your JAVA_HOME to point at that JVM. I have edited my answer with instructions for doing that.
Not yet. Is it correct that I installed ant through apt-get install? If I compile and run CheckVersion.java separately, it shows that I'm having 1.6 version.
OK, does "java" have execute permission? If this is not working for you, please try my suggestion in my last comment (setting JAVA_HOME to the 1.6 install). T
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.