蚂蚁和CLASSPATH

蚂蚁和CLASSPATH

问题描述:

我刚开始在Java中使用书中思想学习Java,用蚂蚁有一些麻烦。

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

我在使用Ubuntu 12.04,并且安装的OpenJDK 7的Java。我还设置了CLASSPATH是code文件夹

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

当我运行code文件夹中的蚂蚁,这是输出:

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)

然而,当我运行Java的版本,这是输出:

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)

如何设置蚂蚁和CLASSPATH是否正确?

How to setup ant and classpath correctly?

P / S:谢谢大家的帮助!我想通了,为什么它不能检查版本。
测试条件是如果(次要&所述;'1';'4'||点&下)中CheckVersion.java。然而,我的版本是1.6.024,eventhough 6> 4,但0。1,这就是为什么它失败了。我想我们需要重写的试验条件!

试试你的JAVA_HOME环境变量设置为您的JDK 1.6的安装目录。

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

当你输入Java的版本命令外壳使用的是第一个Java可执行文件发现在你的PATH。蚂蚁可能会在的bin你的JAVA_HOME目录下的子目录的Java可执行文件。

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.

要找到你的java可执行文件的位置,键入以下内容:

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

您会再设置JAVA_HOME变量/usr/local/java1.6。假设一个Bourne或Bash shell中,该语法将

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