3
votes

I want to make this example to work: https://github.com/graalvm/graal-js-jdk11-maven-demo/blob/master/src/main/java/com/mycompany/app/App.java

But I get an exception in thread "main" java.lang.NoClassDefFoundError: jdk/vm/ci/services/Services

I included GraalVM via Maven

The same exception is thrown in this minimal example

import org.graalvm.polyglot.Context;

public class Main {
    public static void main(String[] args) {
        Context context = Context.create("js");
        context.eval("js", "console.log('Hello from Earth')");
    }
}

The pom

<dependencies>
  <!-- https://mvnrepository.com/artifact/org.graalvm.sdk/graal-sdk -->
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>19.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.graalvm.js/js -->
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>19.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.graalvm.js/js-scriptengine -->
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>19.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.graalvm.compiler/compiler -->
<dependency>
<groupId>org.graalvm.compiler</groupId>
<artifactId>compiler</artifactId>
<version>19.1.1</version>
</dependency>
</dependencies>

I am using jdk-12.0.1 (Open JDK) and working on a Windows 10 computer.

Somewhere on the internet I found that this

 -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler

should be included as VM arguments. When I do that the exception changes to:

Exception in thread "main" java.lang.IllegalAccessError: class org.graalvm.compiler.truffle.runtime.hotspot.AbstractHotSpotTruffleRuntimeAccess (in unnamed module @0x2d8e6db6) cannot access class jdk.vm.ci.services.Services (in module jdk.internal.vm.ci) because module jdk.internal.vm.ci does not export jdk.vm.ci.services to unnamed module @0x2d8e6db6

Maybe there is a problem with the modules: modules-info.java

module App {
exports testinggraal;

requires org.graalvm.sdk;
requires java.scripting;
requires org.graalvm.truffle;
requires org.graalvm.js;
 }
2

2 Answers

3
votes

I'm the author of https://github.com/graalvm/graal-js-jdk11-maven-demo and I looked into this, seems the problem is that the profiles are set up to work only with JDK11.

If you apply the following patch to the pom file of graal-js-jdk11-maven-demo it should work with JDK12 as well (as show by https://travis-ci.org/graalvm/graal-js-jdk11-maven-demo/jobs/564052535)

diff --git a/pom.xml b/pom.xml
index e2a76c1..95cfa2c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,7 +15,7 @@
     <profile>
         <id>jdk11</id>
         <activation>
-                <jdk>11</jdk>
+                <jdk>[11,</jdk>
         </activation>
         <dependencies>
             <dependency>
-1
votes

have same issue with GraalVM 21.3.0 I stopped using the graal vm and trying to use regular 11 vm with graal compiler as a dependency cause the graal vm makes all really slower comparing to regular vm.

I am using springboot, and add graal compiler to dependency to ensure its exitance. the activation tag not make any differnet in my case

I can only guess it is some class loading issue. but not sure what exactly