Run Java task in ant using a different JRE

ant, java

Solution

I used the following:

<java classname="mypackage.myTest"
          jvm="${java_17.home}/bin/java.exe" fork="true">

The `jvm` can determine the command used for executing java. I gave it the path to my 1.7 JDK. It's important to have `fork="true"`, otherwise ant won't run a different java...

Problem

I try to execute a java class using Ant. I used the task ``` <java... > ``` But when it runs I get this: ``` java.lang.UnsupportedClassVersionError: mypackage/myTest: Unsupported major.minor version 51.0 at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:194) ... ``` My ant is not running on Java 1.7. I saw that for a javac task, you can specify `target` to set the java version. Is there a way to specify a specific JDK to be used with the java task?

Original source