Running Java task in ant using a different JRE

I am trying to execute a java class using Ant. I used the task

<java... > 

But when it starts, I get the following:

 java.lang.UnsupportedClassVersionError: mypackage/myTest: Unsupported major.minor version 51.0 at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:194) ... 

My ant does not work on Java 1.7. I saw that for the javac task you can specify the target to install the java version. Is there a way to specify a specific JDK to use with a java task?

+4
source share
2 answers

I used the following:

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

jvm can determine the command used to execute java. I gave him the path to my 1.7 JDK. It is important to have fork="true" , otherwise ant will not start another java ...

+5
source

specify the java compiler you want while doing javac in ANT build.xml

 <javac srcdir="${src.dir}" destdir="${dist.dir.classes}" compiler="javac1.6" executable="D:\jdk1.6.2_05\bin\javac" /> 
+2
source

Source: https://habr.com/ru/post/1492549/


All Articles