I have seen posts with screenshots here and also in the docs, suggesting that one can still have Nashorn for old JS scripts and also have the new JSScripting installed. Then one can choose which one to use for inline scripts in rules (different mime types).
So, I tried to accomplished that and destroyed by OH installation. Luckily, I had a recent backup.
This is what I did:
I had installed JavaScript Scripting (Nashorn) [3.3.0.0;4.0.0.0).
I had not installed JavaScript Scripting (Nashorn) 4.1.0.
I had not installed JavaScript Scripting.
Then I installed JavaScript Scripting 4.1.0. Then I was able to use new features in a rule script.
However, for new rules, there was no choice between Nashorn and the new JS engine.
Old scripts started and failed. Also, transformations with ā.jsā files failed because no engine for ā.jsā files.
So, I uninstalled JavaScript Scripting 4.1.0 again, but this did not fix the issues.
Then i thought, maybe uninstall and reinstall Nashorn would help.
I uninstalled the 3.3.0.0;4.0.0.0 version of Nashorn but then the add-on with this version was not available anymore to reinstall. So I installed Nashorn 4.1.0.
This still did not fix the issues with existing scripts and JS transformations. Nashorn 4.1.0 seemingly only wants to handled scripts with the new mime type āapplication/javascript;version=ECMAScript-2021ā.
Then I gave up and restored the backup.
Can anyone please explain how I get to the point that I have Nashorn still working and handling mime type āapplication/javascriptā, including JS transformations in .js files and also be able to create new rule scripts with mime type āapplication/javascript;version=ECMAScript-2021ā?
I believe you misread those.
And to be frank it is a bad idea to attempt at all youāre creating a barely maintainable mess of a system.
Better migrate your Nashorn rules right away. Less work and trouble in the end.
You need to make sure that the rule āknowsā whether to execute the code as Edition 5.1 or Edition 11 (in reference to your screenshot).
For each single rule click in the config settings on the ā>ā symbol of this setting:
execute an inline script >
and select the correct edition. They should work now.
This way you can migrate your rules 1:1 over time.
At this point you have the correct add-ons installed. The 3.3.0;4.0.0.0 version is only for OH 3. You need the Nashorn 4.1 add-on.
Correct. āapplication/javascriptā will be executed using the JS Scripting addon. Thatās how you tell OH which automation add-on to run that script. One of the breaking changes the release announcement for OH 4 discusses is you need to change the mime type of your Nashorn scripts to continue to use Nashorn JS.
Your JS Script transformations should work though. The old Nashorn transformations should be compatible with the new GraalVM JS.
You canāt. You have to change the mime type to have them run on Nashorn.
You canāt you have to use āapplication/javascriptā as the mime type for the new JS Scripting addon.
Thatās because at that point you had the wrong and a non-working version of the Nashorn add-on installed.
tl;dr:
You must remove the Nashorn 3.3.0.0;4.0.0.0 add-on installed from the Marketplace
You must install the JS Scripting automation add-on from the add-on store
You must install the Nashorn automation add-on from the add-on store
You must set the mime type for the Nashorn scripts to āapplication/javascript;version=ECMAScript-5.1ā
You must set the mime type for the JS Scripting scripts to āapplication/javascriptā
Your JS transformations should work as is once the correct add-ons are installed; but note that they will be executed using the JS Scripting add-on. You have to change the JS(...) to NASHORNJS() to have them executed with the Nashorn add-on.
2024-03-21 07:15:54.500 [ERROR] [.module.script.profile.ScriptProfile] - Failed to process script ābytes.jsā: Script type ājsā is not supported by any available script engine.
This is the script ābytes.jsā:
(function(i) {
return i + "B";
})(input)
I guess, if all add-ons are installed correctly, this should still work.
Everything worked exactly as @rlkoshak wrote. After installation and changing the rule mime types, all old Nashorn scripts and transformations still worked. The simple transformation scripts did not need to be changed to the Nashorn mime type.
I have now also converted some old DSL rules (yes, still also have those) to the new JSScripting.