texu
texu

Reputation: 81

FileSystemNotFoundException when init Graal in Springboot

I add graal libs in my project to execute JavaScript in Java. My project worked on spingboot framework.

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. If I run my project with "gradle bootRun" or IDEA directly, graal init success and work fine;
  2. If I buid my project to a fat jar, which contains all libs in it, graal init failed and throw a 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)
    

I debug the ponit in exception stack, and found that graal want to init "lauguage" configuration file in js-1.0.0-rc9.jar. But in the above scenarios, it used different URI schema.

 - 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.

So, how can I init graal in springboot fat jar?

Upvotes: 6

Views: 633

Answers (1)

texu
texu

Reputation: 81

As a workaround, I unpack graal related libs from fat jar, which is support by springboot. Then graal init successed. In runtime env, path of unpacked libs look like this:

/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

In my project's build.gradle, below part need be added

bootJar {
    requiresUnpack '**/js-*.jar'
    requiresUnpack '**/regex-*.jar'
    requiresUnpack '**/truffle-api-*.jar'
    requiresUnpack '**/graal-sdk-*.jar'
}

More details ref: https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/gradle-plugin/reference/html/#packaging-executable-configuring-unpacking

Upvotes: 2

Related Questions