简体   繁体   English

蚂蚁没有使用正确的Java版本

[英]Ant not using the correct java version

I generated an ant file via Eclipse Juno on a Unix machine where Java jdk (and jre) 1.6 are installed. 我在安装Java jdk(和jre)1.6的Unix机器上通过Eclipse Juno生成了一个ant文件。 When running ant outside of eclipse, where the build.xml file is located, on that machine, everything goes smoothly. 在该机器上在build.xml文件所在的eclipse之外运行ant时,一切都会顺利进行。

Now, the problem is when I try to run ant on another machine, where jdk and jre 1.6 are both installed. 现在,问题是当我尝试在安装了jdk和jre 1.6的另一台计算机上运行ant时。 Here is what I get, on that other machine, which is running RedHat 3 (can't change it): 这是我在另一台运行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

And when I add this line in the build.xml file, I get the following results 当我在build.xml文件中添加此行时,我得到以下结果

build.xml:
<echo message="Java version: ${ant.java.version}"/>

> ant 
  [echo] Java version: 1.4

and compilation errors: 和编译错误:

  [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]           ^
...

Now, the question is: Is my java installation incorrect? 现在,问题是:我的java安装不正确吗? Am I doing something wrong with ant? 我用蚂蚁做错什么了吗?

Here's a quick extract of the build.xml file: 以下是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>

Help is welcome :) 欢迎帮助:)

Your version of ant was compiled against an older version of java (2003). 您的ant版本是针对Java的旧版本(2003)编译的。 Java 1.6 came out in 2006. As I've found out, you can make ant run on an older version like here: http://www.coderanch.com/t/108814/tools/jdk-version-build-xml : Java 1.6于2006年问世。据我所知,您可以使ant在像这样的旧版本上运行: http : //www.coderanch.com/t/108814/tools/jdk-version-build-xml

............... ......

If Ant has been compiled against 1.5 then you can modify the build task to 如果Ant是针对1.5编译的,则可以将构建任务修改为

<javac source="1.4" target="1.4" ...> ...................... But not the other way around. <javac source="1.4" target="1.4" ...> ......................但并非相反。 So I'm guessing you need a fresher version of Ant. 因此,我猜测您需要较新版本的Ant。

From http://ant.apache.org/faq.html#java-version 来自http://ant.apache.org/faq.html#java-version

Redhat ES 3.0 comes installed with ant 1.5.2. Redhat ES 3.0附带了ant 1.5.2。 Even if you have your PATH and ANT_HOME variables set correctly to a later version of ant, you will always be forced to use the preinstalled version. 即使您将PATH和ANT_HOME变量正确设置为更高版本的ant,也始终会被迫使用预装版本。

To use a later version of ant on this OS you could do the following: 要在此OS上使用更高版本的ant,可以执行以下操作:

$ ant -version
Apache Ant version 1.5.2-23 compiled on November 12 2003
$ su -
# rpm -e ant ant-libs
# exit
$ hash -r
$ ant -version
Apache Ant version 1.6.2 compiled on July 16 2004

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM