gpt4 book ai didi

javascript - 在 Springboot 中初始化 Graal 时出现 FileSystemNotFoundException

转载 作者:数据小太阳 更新时间:2023-10-29 05:31:13 26 4
gpt4 key购买 nike

我在我的项目中添加了 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'
  1. 如果我直接使用“gradle bootRun”或 IDEA 运行我的项目,graal init 成功并且工作正常;
  2. 如果我将我的项目构建到一个包含所有库的 fat 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?

最佳答案

作为解决方法,我从 fat jar 中解压 graal 相关的库,这是由 springboot 支持的。然后graal init就成功了。在运行时环境中,解压库的路径如下所示:

/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'
}

更多详情引用: https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/gradle-plugin/reference/html/#packaging-executable-configuring-unpacking

关于javascript - 在 Springboot 中初始化 Graal 时出现 FileSystemNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53512250/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com