我在我的项目中添加了graal库来执行Java中的JavaScript。我的项目使用的是spingboot框架。
compile group: 'org.graalvm.sdk', name: 'graal-sdk', version: '1.0.0-rc9'
compile group: 'org.graalvm.js', name: 'js', version: '1.0.0-rc9'
compile group: 'org.graalvm.js', name: 'js-scriptengine', version: '1.0.0-rc9'
compile group: 'org.graalvm.tools', name: 'profiler', version: '1.0.0-rc9'
compile group: 'org.graalvm.tools', name: 'chromeinspector', version: '1.0.0-rc9'
compile group: 'org.graalvm.truffle', name: 'truffle-api', version: '1.0.0-rc9'
如果我将项目投标到包含所有库的胖罐子中,则初始化初始化失败并抛出FileSystemNotFoundException。
java.nio.file.FileSystemNotFoundException: null
at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:169)
at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:155)
at java.base/java.nio.file.Paths.get(Paths.java:143)
at com.oracle.truffle.polyglot.LanguageCache.collectLanguages(LanguageCache.java:284)
at com.oracle.truffle.polyglot.LanguageCache.createLanguages(LanguageCache.java:211)
at com.oracle.truffle.polyglot.LanguageCache.languages(LanguageCache.java:201)
at com.oracle.truffle.polyglot.PolyglotEngineImpl.initializeLanguages(PolyglotEngineImpl.java:480)
at com.oracle.truffle.polyglot.PolyglotEngineImpl.<init>(PolyglotEngineImpl.java:168)
at com.oracle.truffle.polyglot.PolyglotEngineImpl.<init>(PolyglotEngineImpl.java:152)
at com.oracle.truffle.polyglot.PolyglotImpl.buildEngine(PolyglotImpl.java:197)
at org.graalvm.polyglot.Engine$Builder.build(Engine.java:488)
at org.graalvm.polyglot.Context$Builder.build(Context.java:1083)
at org.graalvm.polyglot.Context.create(Context.java:660)
at ocpm.pcf.policyengine.engine.cache.JavaScriptPolicyParser.graalParse(JavaScriptPolicyParser.java:48)
我调试了异常堆栈中的ponit,发现graal希望在js-1.0.0-rc9.jar中初始化“启动”配置文件。但是在上述情况下,它使用了不同的URI模式。
- In the first scenario, the URI is "jar:file:/C:/Users/texu/.gradle/caches/modules-2/files-2.1/org.graalvm.js/js/1.0.0-rc9/25f41dd171dfa5c5921bc1f6bbdf7860279fc43c/js-1.0.0-rc9.jar!/META-INF/truffle/language", which is a normal file path;
- In the second scenario, the URI is "jar:file:/app/policy-engine.jar!/BOOT-INF/lib/js-1.0.0-rc9.jar!/META-INF/truffle/language", which is a path of nested jar.
那么,如何在springboot胖子罐中初始化graal?
答案 0 :(得分:1)
作为一种解决方法,我从胖子罐中解压缩与graal相关的库,这是springboot的支持。然后graal初始化成功。 在运行时环境中,解压缩的库的路径如下所示:
/tmp/policy-engine.jar-spring-boot-libs-19affd93-0dd2-451a-b469-75fe0c4f458d/js-scriptengine-1.0.0-rc9.jar
/tmp/policy-engine.jar-spring-boot-libs-19affd93-0dd2-451a-b469-75fe0c4f458d/js-1.0.0-rc9.jar
在我的项目的build.gradle中,需要添加以下部分
bootJar {
requiresUnpack '**/js-*.jar'
requiresUnpack '**/regex-*.jar'
requiresUnpack '**/truffle-api-*.jar'
requiresUnpack '**/graal-sdk-*.jar'}