1

My build.xml has a javah task in it. The javah task no longer works with Java 10 and higher, so I added nativeHeaderDir to a javac task, and it is working fine. However, I still want to keep the javah task, so that the same build.xml works for older Java.

How can I make ant skip the javah task only when running with Java 10 and higher? More generally, is there any way to switch the execution path in build.xml, depending on the Java version? Or, is there any other standard way to migrate a javah task from old Java to Java 10/11 with backward-compatibility being maintained?

Rei
  • 29
  • 3

1 Answers1

1

Use a <javaversion> condition supported by Ant 1.10.2 or above.

From the Ant mailing list:

Recent versions of Ant (starting 1.10.2) have a "javaversion" condition which you can use to setup a "property" which can then be used with "if"/"unless" attribute on a target. Here's an example:

<target name="the-one-which-has-javah-task" depends="check-java-version"
unless="java10+">
    ...
</target>   

<target name="check-java-version">
    <condition property="java10+">
      <javaversion atleast="10"/>
    </condition>
</target>
martin clayton
  • 76,436
  • 32
  • 213
  • 198
Rei
  • 29
  • 3
  • 1
    Welcome Rei. When referencing external material in answers please include enough information to form a complete answer without having to follow the link. – martin clayton May 08 '19 at 07:35