Filter löschen
Filter löschen

Why won't MATLAB find the java nashorn ScriptEngine?

3 Ansichten (letzte 30 Tage)
jackson k
jackson k am 9 Mai 2016
Kommentiert: raym am 30 Sep. 2023
MATLAB seems to not want to recognize the nashorn javascript engine that is embedded in java.
First, let me make it clear that the nashorn engine is only available in java 1.8. I am using MATLAB R2015b and I have set the MATLAB_JAVA environment variable to C:\Program Files\Java\jdk1.8.0_91\jre. This has been verified with
version -java
ans =
Java 1.8.0_91-b14 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
manager = javaObject('javax.script.ScriptEngineManager');
engine = manager.getEngineByName('nashorn');
After executing this code, engine is empty (null). I also tried
list = manager.getEngineFactories();
This returns an empty list, meaning that it cannot find any javascript engines. I'm thinking this might be a classloader issue? ScriptEngineManager has an overloaded constructor that allows you to pass in your own classloader but I haven't gotten that to work either. Any help is greatly appreciated.
  2 Kommentare
Stav
Stav am 8 Dez. 2016
I am able to reproduce on a Win7 x64 sp1 machine. MATLAB 2016a with Java 1.8.0_112.
@jackson k, where you able to make any progress on this. Thanks
raym
raym am 30 Sep. 2023
I am able to reproduce on a Win8.1 x64 MATLAB 2016a with Java 1.8.0_211-b12

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stav
Stav am 10 Dez. 2016
Apparently this problem stems from the fact MATLAB's dynamic class loader makes it appear as if there are no scripting engines (including Nashorn..) available. So I was able to fix this by adding the nashorn JAR to the static classpath:
Add the following line to a file named `javaclasspath.txt` in your preferences directory (you can find out what your preference directory is by running `prefdir` in the MATLAB command line):
[JRE_INSTALL_DIR]\lib\ext\nashorn.jar
(replace [JRE_INSTALL_DIR] with the path to your JRE installation)
For some hints about how the static classpath can be modified otherwise (including during runtime) see the following article: http://undocumentedmatlab.com/blog/static-java-classpath-hacks

Kategorien

Mehr zu Call Java from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by