Thank you, @BKBK! I really appreciate your assistance.
To make the coding needs clearer using some altered examples, the Nashorn interaction with the javascript engine in my code is not extensive. Once the engine is made available for CF to use, there is a block of hard-coded JavaScript brought in (mostly Javacript functions):
<cfset local.engine.eval(local.scriptBody)>
Next, some dynamically derived JSON data is made available to the engine. (JSON below is defined in scriptBody):
<cfsavecontent variable="local.jsData">
<cfoutput>
var myFirstData = JSON.parse('#JSStringFormat(SerializeJSON(local.firstData))#');
var mySecondData = JSON.parse('#JSStringFormat(SerializeJSON(local.secondData))#');
</cfoutput>
</cfsavecontent>
<cfset local.engine.eval(local.jsData) />
Next, more JavaScript is eval'd. (myFunction is defined in scriptBody):
<cfsavecontent variable="local.jsRunStuff">
var myResults;
myResults = myFunction(myFirstData, mySecondData);
</cfsavecontent>
<cfset local.engine.eval(local.jsRunStuff) />
And last, an invocation is executed with a value returned to CF:
<cfset local.myResults = DeSerializeJSON(local.engine.invokeFunction('getmyResultsAsJSON', [])) />
So, I think the only thing I'd need Graal to do is equivalents of eval and invokeFunction methods. (I'm not quite sure at thie time what each of those methods do.) Hopefully everything else would just be handled by Graal.
It has been a long search. But I can now provide an update. I have been able to create a proof-of-concept of GraalJS in ColdFusion.
The proof-of-concept consists of CFML code that uses GraalJS to evaluate Javascript source code, and produce a result.
Proof-of-Concept
The steps I followed in creating the proof-of-concept
- Create a Maven project
I created a project in Maven. However, I didn't need to install Maven, as ColdFusion 2023 comes with Maven already installed. It is located at C:\ColdFusion2023\cfusion\maven\apache-maven-3.8.6.
To create a Maven project, simply create a new directory under the Maven root.
For example, the directory C:\ColdFusion2023\cfusion\maven\apache-maven-3.8.6\myMvnProject
- Attach POM file to project
Copy the attached pom.xml file to the directory myMvnProject. Examine pom.xml in a text editor. You will see that it contains the 3 dependencies org.graalvm.sdk:graal-sdk, org.graalvm.polyglot:polyglot and org.graalvm.polyglot:js. These are the resources needed to download all the JAR files that GraalJS depends on.
- Add Maven to the Operating System's Environment Variables
I added the following:
Variable Name: MAVEN_HOME
Variable Value: C:\ColdFusion2023\cfusion\maven\apache-maven-3.8.6
I then added
%MAVEN_HOME%\bin
to the PATH environment variable.
- Obtain the JARs required for implementing GraalJS in ColdFusion 2023
The steps I followed:
- Open the Command Prompt (CMD) as Administrator.;
- Use the cd command to navigate to the directory of the Maven project, C:\ColdFusion2023\cfusion\maven\apache-maven-3.8.6\myMvnProject;
- Type the command mvn dependency:copy-dependencies and press <ENTER> to run it.
If all goes well, the command will use the POM file to download the required JAR files.
In addition, the command will automatically create the subfolder /target/dependency within the project directory, and store the JARs there.
For example, my C:\ColdFusion2023\cfusion\maven\apache-maven-3.8.6\myMvnProject\target\dependency folder looks like this:

- Create GraalJS_library folder and copy the GraalJS JARs into it
I created the folder C:\ColdFusion2023\cfusion\GraalJS_library.
Then I copied all the contents from C:\ColdFusion2023\cfusion\maven\apache-maven-3.8.6\myMvnProject\target\dependency to the GraalJS_library folder.
- Configure ColdFusion's JVM for Graal
I did this by modifying the java.args setting in ColdFusion's jvm.config file as follows:
Replace
-Dcoldfusion.classPath={application.home}/lib/updates,{application.home}/lib,{application.home}/gateway/lib,{application.home}/wwwroot/WEB-INF/cfform/jars,{application.home}/bin/cf-osgicli.jar
with
-Dcoldfusion.classPath={application.home}/lib/updates,{application.home}/lib,{application.home}/gateway/lib,{application.home}/wwwroot/WEB-INF/cfform/jars,{application.home}/bin/cf-osgicli.jar,{application.home}/graalJS_library -Dpolyglot.log.file={application.home}/logs/polyglot.log -Dpolyglotimpl.DisableClassPathIsolation=true -Dpolyglot.engine.WarnInterpreterOnly=false
You will find an explanation of the additional Graal flags in the Reference Notes below.
Restart ColdFusion for the changes to take effect.
- Run the proof-of-concept code
<!--- Create GraalJS context, giving it the necessary permissions --->
<cfset context=createObject("java", "org.graalvm.polyglot.Context").newBuilder(["js"]).allowAllAccess(true).allowIO(true).build()>
<!--- Javascript for calculating the square root of a given positive integer --->
<cfset jsCode = 'calculateRoot(param); function calculateRoot(param) { return "The square root of ".concat(param).concat(" is ").concat(Math.sqrt(param)); }'>
<!--- The input: a positive integer --->
<cfset arg = 10>
<!--- Pass the argument from CFML to GraalJS --->
<cfset context.eval("js", "var param=#arg#;")>
<!--- Run GraalJS using the argument --->
<cfset value = context.eval("js", jsCode)>
<cfoutput>#value#</cfoutput>
The result: The square root of 10 is 3.1622776601683795