Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Java task in ant using a different JRE

Tags:

java

ant

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?

like image 766
Gilad Avatar asked Jul 21 '13 07:07

Gilad


People also ask

Which Java does ant use?

You will need Java installed on your system, version 1.8 or later required. The later the version of Java, the more Ant tasks you get.

What is Classpathref in ant?

Ant classpath: discussion dir defined before this code is run, and that variable points to your lib directory, which contains all of the jar files needed by your application. This code also creates a variable named class. path which can be referenced later in your Ant script using the variable syntax ${class. path} .


1 Answers

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...

like image 165
Gilad Avatar answered Oct 29 '22 14:10

Gilad