Apache Ant with Graal VM
Asked Answered
E

3

5

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
Elute answered 3/11, 2021 at 23:37 Comment(0)
C
7

Solution 1

If you are using JDK 15 or above. Please add the below jars to the path.

enter image description here

Solution 2

Using Graal VM Jars

Use the above jars and pass them as a classpathref.

enter image description here

Coxa answered 12/1, 2023 at 14:36 Comment(0)
M
4

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.

Mercenary answered 4/11, 2021 at 10:24 Comment(1)
Solution 1 did the trick: <path id="javax.classpath"> <pathelement location="D:/dependencies/libs/nashorn/nashorn-core-15.4.jar" />? <pathelement location="D:/dependencies/libs/nashorn/asm-9.7.jar" /> <pathelement location="D:/dependencies/libs/nashorn/asm-util-9.7.jar" /> </path> <script language="javascript" manager="javax" classpathref="javax.classpath">Needs
K
0

Add nashorn-core-15.4.jar, asm-9.7.jar, asm-util-9.7.jar, asm-tree-9.7.jar, asm-commons-9.7.jar to the ant\lib folder to work as before.

Klipspringer answered 6/9 at 11:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.