我在安装了 Java jdk(和 jre)1.6 的 Unix 机器上通过 Eclipse Juno 生成了一个 ant 文件。在 Eclipse 之外运行 ant(build.xml 文件所在的位置)时,在该机器上,一切都很顺利。
现在,问题是当我尝试在另一台安装了 jdk 和 jre 1.6 的机器上运行 ant 时。这是我在另一台运行 RedHat 3 的机器上得到的结果(无法更改):
> ant -version
Apache Ant version 1.5.2-23 compiled on November 12 2003
> java -version
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode, sharing)
> javac -version
javac 1.6.0_39
> ls -l `which java`
lrwxrwxrwx 1 root root 26 Feb 13 15:22 /usr/bin/java -> /usr/java/default/bin/java*
> ls -l `which javac`
lrwxrwxrwx 1 root root 27 Feb 13 15:22 /usr/bin/javac -> /usr/java/default/bin/javac*
> ls -l /usr/java
total 8
lrwxrwxrwx 1 root root 16 Nov 7 14:19 default -> /usr/java/latest
drwxr-xr-x 7 root root 4096 Feb 13 15:02 jdk1.6.0_39/
drwxr-xr-x 7 root root 4096 Nov 7 14:18 jre1.6.0_37/
lrwxrwxrwx 1 root root 21 Feb 13 15:03 latest -> /usr/java/jdk1.6.0_39
> echo $JAVA_HOME
/usr/java/jdk1.6.0_39/bin/java
当我在 build.xml 文件中添加这一行时,我得到以下结果
build.xml:
<echo message="Java version: ${ant.java.version}"/>
> ant
[echo] Java version: 1.4
和编译错误:
[javac] ...InputManager.java:11: error: Invalid method declaration, method name required.
[javac] Map<Double, List<MyObject>> loadFile(File pSelectedFile)
[javac] ^
[javac] ...InputManager.java:11: error: Class or interface declaration expected.
[javac] Map<Double, List<MyObject>> loadFile(File pSelectedFile)
[javac] ^
[javac] ...InputManager.java:33: error: Invalid character '@' in input.
[javac] @Override
[javac] ^
...
现在,问题是:我的 java 安装不正确吗?我对蚂蚁做错了吗?
下面是 build.xml 文件的快速摘录:
> vim build.xml
<project basedir="." default="build" name="myProject">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="/opt/eclipse"/> <!-- that is also where eclipse is on my 2nd machine -->
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
[some stuff]
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target depends="init" name="build-project">
<echo message="Java version: ${ant.java.version}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="myProject.classpath"/>
</javac>
</target>
</project>
欢迎帮助:)