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

How to actually install/run GraalJS? #888

Open
Pecacheu opened this issue Feb 8, 2025 · 1 comment
Open

How to actually install/run GraalJS? #888

Pecacheu opened this issue Feb 8, 2025 · 1 comment

Comments

@Pecacheu
Copy link

Pecacheu commented Feb 8, 2025

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.

@fesiqueira
Copy link

@Pecacheu Can you try to make so the js-scriptengine dependency is the above the org.graalvm.polyglot?

I was having the same issue and after making this change I got it to work again. You can find the order I mention here.

Let me know if it helps.

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