Skip to content

Commit

Permalink
Upgrade Java+Javascript Embedding Example to GraalVM for JDK 21 (23.1.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
olyagpl committed Dec 15, 2023
1 parent 5bdf40c commit b57532a
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/polyglot-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
timeout-minutes: 15
strategy:
matrix:
java-version: ['17', 'dev']
java-version: ['21', 'dev']
steps:
- uses: actions/checkout@v3
- uses: graalvm/setup-graalvm@v1
Expand All @@ -34,4 +34,4 @@ jobs:
run: |
cd polyglot-debug
mvn --no-transfer-progress clean package
java -cp ./target/PolyglotDebug-1.0-SNAPSHOT.jar org.graalvm.demos.PolyglotDebug
mvn exec:exec
43 changes: 32 additions & 11 deletions polyglot-debug/README.MD
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
# GraalVM Java to JavaScript Polyglot Debugging
# Debugging a Java with JavaScript Embedding Application

This sample code helps to demonstrate simplicity of debugging and developing GraalVM Polyglot applications using __VS Code extensions__.
This sample code helps to demonstrate simplicity of debugging and developing GraalVM polyglot applications using Visual Studio (VS) Code extensions.

## Prerequisites

1. VS Code has to be installed.
1. Install VS Code and launch it.
2. Then go to VS Code Extensions activity panel and search for _GraalVM Extension Pack_, install it. The GraalVM Extension Pack will install all required extensions.
3. [Install GraalVM in VS Code](https://www.graalvm.org/latest/tools/vscode/graalvm-extension/#graalvm-installation-wizard): Navigate to Gr activity panel in VS Code and install some of the latest GraalVM __Enterprise Edition__ versions available from the list.
2. Open Visual Studio Code, navigate to Extensions activity panel in the left-hand side Activity Bar. Search for “GraalVM” in the search field. Find [GraalVM Tools for Java](https://marketplace.visualstudio.com/items?itemName=oracle-labs-graalvm.graalvm), press Install. Reload will be required.
3. [Install GraalVM in VS Code](https://www.graalvm.org/latest/tools/vscode/graalvm-extension/#graalvm-installation-wizard): Navigate to Gr activity panel in VS Code and install the latest Oracle GraalVM version available from the list.
4. Confirm to set this as _Active GraalVM_ for VS Code.
5. Install the `js` component.

## Debugging the project

Working with Polyglot project in VSCode is simple just open this sample.
## Build and Run the Application

1. Open VS Code Terminal.
2. Clone the repository and navigate into the `polyglot-debug` directory:
```bash
git clone https://github.com/graalvm/graalvm-demos
```
```bash
cd graalvm-demos/polyglot-debug
```

3. Build the application using Maven:
```bash
mvn clean package
```
4. Run this application with the following command:
```bash
mvn exec:exec
```

## Debug the Application

Working with a polyglot project in VS Code is simple just open this sample.
It will be working out of the box with VS Code GraalVM extensions.

Place breakpoints either in Java or JavaScript code.
1. Place breakpoints either in Java or JavaScript code.

2. To debug the project, go to __Run and Debug__ activity or simply press F5.

To debug the project go to __Run and Debug__ activity or simply press F5.
Choose **Launch Java 8+** as this is the Polyglot debugger provided by GraalVM extensions.
3. Choose **Launch Java 8+** as this is the Polyglot debugger provided by the GraalVM extension.

That is, the sample is running under debugger on GraalVM.
105 changes: 100 additions & 5 deletions polyglot-debug/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,107 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.graalvm.demos</groupId>
<artifactId>PolyglotDebug</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<graalvm.version>23.1.1</graalvm.version>
</properties>
<name>PolyglotDebug</name>
</project>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.graalvm.demos.PolyglotDebug</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>--module-path</argument>
<!-- automatically creates the modulepath using all project dependencies -->
<modulepath/>
<argument>-m</argument>
<argument>demo/org.graalvm.demos.PolyglotDebug</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<executable>${JAVA_HOME}/bin/java</executable>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>collections</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>nativeimage</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>word</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>polyglot</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>js</artifactId>
<version>${graalvm.version}</version>
<type>pom</type>
</dependency>
</dependencies>

</project>
4 changes: 4 additions & 0 deletions polyglot-debug/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module demo {
exports org.graalvm.demos;
requires org.graalvm.polyglot;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;
Expand Down

0 comments on commit b57532a

Please sign in to comment.