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?
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.
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} .
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With