Reputation: 145
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
Upvotes: 5
Views: 3663
Reputation: 11
I'm running Netbeans 24 on Win 10 with Graal JDK 21. I solved this problem as follows:
Downloaded the following jars from Maven https://mvnrepository.com/ (I actually just Googled each file name and it brought me to the Maven location for each file)
nashorn-core-15.4.jar
asm-9.4.jar
asm-util-9.4.jar
asm-commons-9.4.jar
asm-tree-9.4.jar
I put these .jars
in the following folder:
C:\Program Files\NetBeans-24\netbeans\extide\ant\lib
In Netbeans Tools>Options>Ant I set Verbosity Level to Debug, ran my program, then switched it back to Normal, not really sure if this is necessary. Restarting Netbeans isn't as bad idea either.
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 314
If you are using JDK 15 or above. Please add the below jars to the path.
Using Graal VM Jars
Use the above jars and pass them as a classpathref.
Upvotes: 7
Reputation: 4565
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.
Upvotes: 4