Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wildcards in classpath do not work anymore #834

Open
j-ulrich opened this issue Jul 10, 2024 · 2 comments
Open

Wildcards in classpath do not work anymore #834

j-ulrich opened this issue Jul 10, 2024 · 2 comments

Comments

@j-ulrich
Copy link

j-ulrich commented Jul 10, 2024

It seems that since GraalJS 22.x, wildcards in the classpath do not work anymore.

Before (21.x), I got this behavior:

$ /Library/Java/JavaVirtualMachines/graalvm-ce-java17-21.3.3.1/Contents/Home/bin/js --version
GraalVM JavaScript (GraalVM CE Native 21.3.3.1)
$ /Library/Java/JavaVirtualMachines/graalvm-ce-java17-21.3.3.1/Contents/Home/bin/js --jvm "--vm.cp=/tmp/jackson/*" --vm.Dpolyglot.js.load-from-classpath=true --vm.Dpolyglot.js.load-from-url=true
> Java.type("com.fasterxml.jackson.core.JsonParser")
JavaClass[com.fasterxml.jackson.core.JsonParser]

with any later version (tested with 22.3.3, 23.0.2 and 24.0.1), I get this:

$ /Library/Java/JavaVirtualMachines/graalvm-ce-java17-22.3.3/Contents/Home/bin/js --version
GraalVM JavaScript (GraalVM CE Native 22.3.3)
$ /Library/Java/JavaVirtualMachines/graalvm-ce-java17-22.3.3/Contents/Home/bin/js --jvm "--vm.cp=/tmp/jackson/*" --vm.Dpolyglot.js.load-from-classpath=true --vm.Dpolyglot.js.load-from-url=true
> Java.type("com.fasterxml.jackson.core.JsonParser")
TypeError: Access to host class com.fasterxml.jackson.core.JsonParser is not allowed or does not exist.
	at <js> :program(<shell>:1:1:0-49)

Java.addToClasspath() with a wildcard does not work either:

> Java.addToClasspath("/tmp/jackson/*")
> Java.type("com.fasterxml.jackson.core.JsonParser")
TypeError: Access to host class com.fasterxml.jackson.core.JsonParser is not allowed or does not exist.
	at <js> :program(<shell>:3:1:0-49)

However, listing the jar files explicitly works:

$ /Library/Java/JavaVirtualMachines/graalvm-ce-java17-22.3.3/Contents/Home/bin/js --jvm "--vm.cp=/tmp/jackson/jackson-core-2.17.2.jar" --vm.Dpolyglot.js.load-from-classpath=true --vm.Dpolyglot.js.load-from-url=true
> Java.type("com.fasterxml.jackson.core.JsonParser")
JavaClass[com.fasterxml.jackson.core.JsonParser]

It seems that before 22.x, the wildcard was expanded at some point:

$ /Library/Java/JavaVirtualMachines/graalvm-ce-java17-21.3.3.1/Contents/Home/bin/js --jvm "--vm.cp=/tmp/jackson/*" --vm.Dpolyglot.js.load-from-classpath=true --vm.Dpolyglot.js.load-from-url=true
> java.lang.System.getProperty("java.class.path")
/Library/Java/JavaVirtualMachines/graalvm-ce-java17-21.3.3.1/Contents/Home/lib/graalvm/graaljs-launcher.jar:/Library/Java/JavaVirtualMachines/graalvm-ce-java17-21.3.3.1/Contents/Home/lib/graalvm/launcher-common.jar:/tmp/jackson/jackson-core-2.17.2.jar

After 22.x, the wildcard appears in the classpath as-is:

$ /Library/Java/JavaVirtualMachines/graalvm-ce-java17-22.3.3/Contents/Home/bin/js --jvm "--vm.cp=/tmp/jackson/*" --vm.Dpolyglot.js.load-from-classpath=true --vm.Dpolyglot.js.load-from-url=true                      
> java.lang.System.getProperty("java.class.path")
/Library/Java/JavaVirtualMachines/graalvm-ce-java17-22.3.3/Contents/Home/languages/js/bin/../../../lib/graalvm/graaljs-launcher.jar:/Library/Java/JavaVirtualMachines/graalvm-ce-java17-22.3.3/Contents/Home/languages/js/bin/../../../lib/graalvm/launcher-common.jar:/tmp/jackson/*

It does not seem to be a problem with GraalVM in general because when printing out the java.class.path in a Java program, it still gets expanded (the program simply prints java.lang.System.getProperty("java.class.path")):

$ /Library/Java/JavaVirtualMachines/graalvm-ce-java17-22.3.3/Contents/Home/bin/java -cp '.:/tmp/jackson/*' GraalClassLoadTest
.:/tmp/jackson/jackson-core-2.17.2.jar
$ /Library/Java/JavaVirtualMachines/graalvm-jdk-17.0.11+7.1/Contents/Home/bin/java -cp '.:/tmp/jackson/*' GraalClassLoadTest
.:/tmp/jackson/jackson-core-2.17.2.jar
@j-ulrich
Copy link
Author

j-ulrich commented Jul 10, 2024

Tested it on macOS and in GraalVM Docker containers.

@woess
Copy link
Member

woess commented Sep 23, 2024

Confirmed. I think this was caused by the switch to thin language launchers. It was kind of working by accident before.

You can work around it by doing the expansion yourself (via command line (shell) or Java.addToClasspath + host interop). Or you could try to use module path.

We'll probably implement launcher support for this eventually, but it's not a priority for us right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants