我在我的项目中添加了 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'
- 如果我直接用“gradle bootRun”或IDEA运行我的项目,graal init成功并且工作正常;
如果我将我的项目构建到一个包含所有库的胖 jar 中,graal init 会失败并抛出 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 中初始化“lauguage”配置文件。但在上述场景中,它使用了不同的 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 fat jar中初始化graal?