这是indexloc提供的服务,不要输入任何密码
Skip to content

How to actually install/run GraalJS? #888

@Pecacheu

Description

@Pecacheu

I'm trying to update project that previously worked just fine on GraalVM for JDK 17. On the older version, you install JS via gu install js and then ScriptEngine just works. Nice and simple. On the newer versions, not so much. gu is now removed and not supported, so how do I install JS into GraalVM? I'm using Maven, and I've tried adding all these dependencies to my pom.xml as described:

<properties>
	<java.version>23</java.version>
	<graalvm.version>24.1.0</graalvm.version>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependency>
	<groupId>org.graalvm.polyglot</groupId>
	<artifactId>polyglot</artifactId>
	<version>${graalvm.version}</version>
</dependency>
<dependency>
	<groupId>org.graalvm.js</groupId>
	<artifactId>js-scriptengine</artifactId>
	<version>${graalvm.version}</version>
</dependency>
<!-- runtime -->
<dependency>
	<groupId>org.graalvm.polyglot</groupId>
	<artifactId>js-community</artifactId>
	<version>${graalvm.version}</version>
	<type>pom</type>
	<scope>runtime</scope>
</dependency>
<dependency>
	<groupId>org.graalvm.polyglot</groupId>
	<artifactId>profiler-community</artifactId>
	<version>${graalvm.version}</version>
	<type>pom</type>
	<scope>runtime</scope>
</dependency>
<dependency>
	<groupId>org.graalvm.polyglot</groupId>
	<artifactId>inspect-community</artifactId>
	<version>${graalvm.version}</version>
	<type>pom</type>
	<scope>runtime</scope>
</dependency>

I then set my JDK to GraalVM 23 (GraalJS 24.1.0 said to use GraalVM 23) in IntelliJ and build with clean package. On my Linux server, I install the same GraalVM version into /usr/lib/jvm/graalvm. Then I run my JAR using JAVA_HOME=/usr/lib/jvm/graalvm /usr/lib/jvm/graalvm/bin/java -jar <name>

Important part of the code:

ScriptEngineManager manager = new ScriptEngineManager();
engine =  manager.getEngineByName("graal.js");
if(engine == null) throw new Exception("Engine not found!");

Problem is, engine is always null. Again, running the same code on the previous version with gu install js, this all works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions