Apache Ant with Graal VM

Viewed 452

We use Apache Ant with Nashorn JavaScript Engine, which became deprecated and removed in jdk 15 and up. I trying find how to switch from Nashorn to Graal VM and didn't find any usable information even on Apache web-site. Please advise which jars I need and were should I put them. what need to be changed in code we have. If somebody already did it, please share your experience. I have a sample, which run against jdk1.8.0_311:

<?xml version="1.0" ?>
<project name="test" default="test">
    <property environment="env"/>   
    <target name="test" >
        <script language="javascript">          
            <![CDATA[
            load("nashorn:mozilla_compat.js");
            importPackage(java.time);
            var today = new Date();
            var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
            self.log("This script is for Test Of Nashorn Javascript Engine");
            print ("Today is: " + date );
            ]]>
        </script>
    </target>
</project>

Result looks like:

test:
   [script] Warning: Nashorn engine is planned to be removed from a future JDK release
   [script] This script is for Test Of Nashorn Javascript Engine
   [script] Today is: 2021-11-3

BUILD SUCCESSFUL
Total time: 0 seconds
1 Answers

You could also add standalone Nashorn as a dependency to your Ant build; putting it in your Ant lib directory should work. By default that's $ANT_HOME/lib but some Ant installations use a different location, e.g. homebrew-installed Ant will use /usr/local/share/ant. If you don't want to put it in the lib, you can also put it with your project and use <classpath> or <classpathref> within the <script> tag to point to it.

Mind you, standalone Nashorn also needs ASM 7.3.1 on the classpath. JARs for both can be downloaded from Maven Central.

Related