Why won't MATLAB find the java nashorn ScriptEngine?

조회 수: 5 (최근 30일)
jackson k
jackson k 2016년 5월 9일
댓글: raym 2023년 9월 30일
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
Stav
Stav 2016년 12월 8일
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 2023년 9월 30일
I am able to reproduce on a Win8.1 x64 MATLAB 2016a with Java 1.8.0_211-b12

댓글을 달려면 로그인하십시오.

답변 (1개)

Stav
Stav 2016년 12월 10일
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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by