Using GraalJS in the scripting plugin
Starting with release v0.2.0 the JOSM Scripting Plugin requires Java 11 (or higher). To use the plugin, you have to run JOSM with a Java 11 compatible JDK.
You have two options:
-
Run JOSM with the Java 11 (or Java 17) compatible JDK provided by Oracles GraalVM
-
Run JOSM with another Java 11 (or higher) compatible JDK, for instance with the OpenJDK
Running JOSM with GraalJS
Running JOSM with a stock JDK and GraalJS as java library
JDKs other than GraalVM don’t include GraalJS. You have to download the jar files required for GraalJS and ensure they are on the classpath when you start JOSM.
-
Download GraalJS jar files
The jar files required for GraaLJS are available from this github repository. Download the ZIP file with the latest release from this repository.
-
Start JOSM with the GraalJS jar files on the classpath
Refer to this README file.
Running JOSM with the GraalVM JDK
GraalVM ships with an engine for JavaScript (compatible with EMCAScript 2021) called GraalJS. When you run JOSM with the JDK provided by the GraalVM, GraalJS is available in the scripting plugin and you can execute scripts written in JavaScript using GraalJS.
-
Download GraalVM 22.1 (or higher) and install it.
- Make sure the environment variable
JAVA_HOME
refers to your GraalVM installation. - Make sure the java binaries (in particular
java
) shipped with the GraalVM are on your path (thePATH
environment variable has to be set).
Refer to the GraalVM quickstart guide for additional help.
- Make sure the environment variable
-
Check your installation with the command
java -version
. It should output information about the Java SDK shipped by the GraalVM, for instance:openjdk version "11.0.15" 2022-04-19 OpenJDK Runtime Environment GraalVM CE 22.1.0 (build 11.0.15+10-jvmci-22.1-b06) OpenJDK 64-Bit Server VM GraalVM CE 22.1.0 (build 11.0.15+10-jvmci-22.1-b06, mixed mode, sharing)
-
Launch JOSM
In the simplest case:
# make sure 'java' is resolved to the java binary shipped with the GraalVM $ java -jar josm.jar # or on Windows: C:> java.exe -jar josm.jar
Add additional command line options, if necessary, for instance:
# make sure 'java' is resolved to the java binary shipped with the GraalVM $ java -Djosm.home=/your/josm/home -Xmx2G -jar josm.jar # or on Windows: C:> java.exe -Djosm.home=c:\\your\\josm\\home -Xmx2G -jar josm.jar
Using the JavaScript API V3
The scripting plugins ships with a JavaScript API. API V3 can only be used in the GraalJS scripting engine. It can’t be used with JSR223-compatible scripting engines for JavaScript. In particular, it can neither be used with Mozilla Rhino nor with Oracle Nashorn.
API V3 has the following main features:
- loading and using ECMAScript Modules (ES Modules) modules
- lookup, add, delete, and remove layers
- load data into a layer, save data from a layer
- download objects and changesets from the OSM server, upload objects and changesets to the OSM server
- create data sets
- create nodes, ways, and relations in a data set
- update nodes, ways, and relations
- query data sets for nodes, ways, or relations
- create undoable/redoable change objects to update nodes, ways, and relations
- write to the scripting console
Refer to the API V3 documentation.