0

This is done with JavaScrupt interpreter shell of GraalVM CE 21.3.0.

Attempting to access some Java class, such as java.io.File results in this error:

TypeError: Access to host class java.io.File is not allowed or does not exist.

When running the shell without any options this much is needed to get the error:

new java.io.File()

When running the shell with --js.java-package-globals=false only this much is required:

Java.type("java.io.File")

How do I fix this problem? If these features are supposed to be provided, then why aren't they working right out of the box?

Melab
  • 2,594
  • 7
  • 30
  • 51

1 Answers1

0

I'm assuming you are missing the --jvm flag to run the js launcher in jvm mode which is required for Java interop.

$ ./graalvm-ee-java11-21.3.0/bin/js --eval 'new java.io.File(""); console.log("OK!")'
TypeError: Access to host class java.io.File is not allowed or does not exist.
        at <js> :program(Unknown)

$ ./graalvm-ee-java11-21.3.0/bin/js --jvm --eval 'new java.io.File(""); console.log("OK!")'
OK!

This is documented here:

To enable Java interoperability, the --jvm option has to be provided to the native launcher

BoriS
  • 907
  • 5
  • 13