javascript - How to use GraalVM in Java? class not found exception - Stack Overflow

I want to make this example to work: .javaBut I get an exception in thread "main" java.lang.N

I want to make this example to work: .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>
  <!-- .graalvm.sdk/graal-sdk -->
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>19.1.1</version>
</dependency>
<!-- .graalvm.js/js -->
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>19.1.1</version>
</dependency>
<!-- .graalvm.js/js-scriptengine -->
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>19.1.1</version>
</dependency>
<!-- .graalvmpiler/piler -->
<dependency>
<groupId>org.graalvmpiler</groupId>
<artifactId>piler</artifactId>
<version>19.1.1</version>
</dependency>
</dependencies>

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

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.graalvmpiler.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;
 }

I want to make this example to work: https://github./graalvm/graal-js-jdk11-maven-demo/blob/master/src/main/java//mypany/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./artifact/org.graalvm.sdk/graal-sdk -->
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>19.1.1</version>
</dependency>
<!-- https://mvnrepository./artifact/org.graalvm.js/js -->
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>19.1.1</version>
</dependency>
<!-- https://mvnrepository./artifact/org.graalvm.js/js-scriptengine -->
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>19.1.1</version>
</dependency>
<!-- https://mvnrepository./artifact/org.graalvm.piler/piler -->
<dependency>
<groupId>org.graalvm.piler</groupId>
<artifactId>piler</artifactId>
<version>19.1.1</version>
</dependency>
</dependencies>

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

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.piler.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;
 }
Share Improve this question edited Jul 29, 2019 at 22:55 asked Jul 25, 2019 at 23:49 user5354385user5354385 0
Add a ment  | 

1 Answer 1

Reset to default 3

I'm the author of https://github./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/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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745621701a4636557.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信