Prokop Hapala
Prokop Hapala

Reputation: 2444

Ant use old jdk - how to change it?

I have eclipse indigo (3.7.2) on Ubuntu 12.04 64 bit and I try to compile project using java 1.7. I think I have installed java 1.7 properly because, I can run processing 2.0 (which use java 1.7) and I get correct version message:

prokop@prokop-Precision-T1500:~$ java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

however, when hit "play" in Ant in eclipse I get following message:

 Unsupported major.minor version 51.0

also in header caption of "Console" window of ant build output is :

[Ant Build] /usr/lib/jvm/java-6-openjdk/bin/java

I tried to modify environment settings of eclipse:

but it does not help - ant is oviously still using java-6-openjdk

Upvotes: 3

Views: 8718

Answers (4)

Impresi MLine
Impresi MLine

Reputation: 62

Another way to set this, is to use in your build.xml:

<project name="xyz" default="all">
<property name="ant.build.javac.target" value="1.7" />
...

This global parameter (ant.build.javac.target) specifies the project target to be compatible with JDK 7.

Upvotes: 1

indika
indika

Reputation: 923

This occurs when you run ant via eclipse. You can set JDK using External tools configuration in Eclipse. See the attachment.

External tools configuration in eclipse

Upvotes: 3

Kasper Ziemianek
Kasper Ziemianek

Reputation: 1349

Ant uses JAVA_HOME. Try echo $JAVA_HOME in shell to see where it's pointing and point it to jdk 7.

Point 4 in following manual :
http://ant.apache.org/manual/install.html

Nice explanation can be found here : https://unix.stackexchange.com/questions/123412/what-is-the-difference-between-java-home-and-update-alternatives

Upvotes: 2

VikramV
VikramV

Reputation: 1111

In the javac task, try specifying the Java compiler by setting the executable attribute as follows:

<property name="JDK1.7.dir" location="/usr/lib/jvm/java-7" />
<property name="javac1.7" location="${JDK1.7.dir}/bin/javac" />

<target name="compile-tests">
  <javac executable="${javac1.7}" 
      fork="yes"
      includeantruntime="false" 
      srcdir="${test.dir}"
      destdir="${build.dir}" >
    <classpath refid="class.path" />
  </javac>
</target>

Upvotes: 0

Related Questions