electronic.alchemy :: graalvm-for-unsupported-platforms
electronic.alchemy
where the past meets the future
projects > openhab > graalvm-for-unsupported-platforms

graalvm-for-unsupported-platforms

Created by hww3. Last updated by hww3, 3 hours ago. Version #4.

openHAB’s modern scripting language support relies on the GraalVM Polyglot language framework, which provides access to multiple languages from within a Java language. Somewhere around GraalVM 24, a set of new features was added that provide deep integration with native operating system binaries. At that time, support for these features was limited to a subset of platforms that the greater Java language is able to run on, and after this point, trying to access polyglot features (among other things) would fail to work due to an UnsupportedPlatformException being thrown by GraalVM. Note that this error is thrown regardless of whether a feature that required native platform support was being used. 

A fix was subsequently made to GraalVM that should provide a workaround, and that landed in the GraalVM source tree around June 2025. It has not yet made it into an official release as of April 2026.
The solution to the problem is to simply point the various openhab components to a version of the GraalVM libraries that incorporate the fix. 

Unfortunately ue to a variety of factors, (openHAB’s use of OSGI, GraalVM’s complicated build process, the complexity of getting Maven to do something that’s outside what it considers to be “good practice”, etc), it’s actually quite complicated to make that happen. I’ve got quite a bit of Java development experience, and getting to the procedure I’m about to describe took me about 24 working hours. A lot of that was chasing dead ends.

1. Get a copy of the latest graalvm development builds. Theoretically you could build it all yourself, but I wasted my first day trying to make sense of what was going on. 

https://github.com/graalvm/graalvm-ce-dev-builds/releases

You’ll want the maven-resource-bundle-community-dev.tar.gz bundle, which is buried in the full list of downloads.  Save and unpack the archive someplace. 

<2. Get a copy of the openhab-osgiify repository. We will use it to generate osgi bundles of the development version of GraalVM that has the fix we need.

3. Set up a web server that will serve the contents of the maven resource bundle. This will allow maven to download “snapshot” versions of the graalvm libraries needed to generate the OSGI bundles, as well as to compile the various openhab components we’ll need to produce.

Note: While the maven resources bundle is a valid maven repository, the files are stored with filenames (that include the instant the snapshot was built) that maven will only use if they’re served via a web server. 

4. Modify the pom.xml in openhab-osgiify project. Apply the following changes (update the dummy repository url to match wherever you’re serving the maven resources bundle from.

diff --git a/pom.xml b/pom.xml
index dabb801..a2d3abb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,7 +67,8 @@
     org.graalvm.js.js-scriptengine
     org.graalvm.llvm.llvm-api
     org.graalvm.polyglot.polyglot
-    org.graalvm.python.python-embedding
+
     org.graalvm.python.python-language
     org.graalvm.python.python-resources
     org.graalvm.regex.regex
@@ -108,6 +109,20 @@
     https://github.com/openhab/openhab-osgiify/issues
   
 + 
+        
+            openhab-snapshot
+            My Custom Repository
+            http://localhost:80/
+            
+                false
+            
+            
+                true
+            
+        
+    
+
   
     UTF-8
     UTF-8
@@ -115,7 +130,7 @@
     unknown
     unknown
     ${project.version}
-    25.0.1
+    25.1.0-SNAPSHOT
   
    
	
 >Note: I disabled the python-embedding module because there seemed to be a missing jar in the maven bundle. I didn’t investigate this further, as I’m not using python, but it’s hopefully a straightforward fix.

5. Then, run “mvn clean spotless:apply install” to build the OSGI bundles and install them in your local maven repository (needed to actually build the openHAB components.)

6. Clone the openhab-addons repository from github. This has the automation addons that we’ll need to rebuild against our snapshot libraries.

7. In openhab-addons, edit pom.xml, making the following changes:

diff --git a/pom.xml b/pom.xml
index acea21b0b3..67bf0586c1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,6 +35,20 @@
     itests
   
 +  
+    
+      
+        false
+      
+      
+        true
+      
+      openhab-snapshot
+      My Custom Repository
+      http://localhost:80/
+    
+  
+
   
     scm:git:https://github.com/openhab/openhab-addons.git
     scm:git:https://github.com/openhab/openhab-addons.git
@@ -73,7 +87,7 @@
     4.4.8
     5.19.0
     4.1.126.Final
-    25.0.1
+    25.1.0-SNAPSHOT
     4.12.0
     3.9.0
     2.13.1
Also, apply the following changes to src/main/feature/feature.xml (NOTE: the urls I’m providing below are temporary, and probably won’t be available for long. I recommend making a copy of them, or building them yourself from the openhab-osgiify project.)

diff --git a/bundles/org.openhab.automation.jsscripting/src/main/feature/feature.xml b/bundles/org.openhab.automation.jsscripting/src/main/feature/feature.xml
index ecbdd3b3e0..3bced995c0 100644
--- a/bundles/org.openhab.automation.jsscripting/src/main/feature/feature.xml
+++ b/bundles/org.openhab.automation.jsscripting/src/main/feature/feature.xml
@@ -5,19 +5,19 @@
         
                openhab-runtime-base
-               mvn:org.openhab.osgiify/org.graalvm.js.js-language/25.0.1
-               mvn:org.openhab.osgiify/org.graalvm.js.js-scriptengine/25.0.1
-               mvn:org.openhab.osgiify/org.graalvm.regex.regex/25.0.1
-               mvn:org.openhab.osgiify/org.graalvm.polyglot.polyglot/25.0.1
-               mvn:org.openhab.osgiify/org.graalvm.sdk.collections/25.0.1
-               mvn:org.openhab.osgiify/org.graalvm.sdk.jniutils/25.0.1
-               mvn:org.openhab.osgiify/org.graalvm.sdk.nativeimage/25.0.1
-               mvn:org.openhab.osgiify/org.graalvm.sdk.word/25.0.1
-               mvn:org.openhab.osgiify/org.graalvm.shadowed.icu4j/25.0.1
-               mvn:org.openhab.osgiify/org.graalvm.shadowed.xz/25.0.1
-               mvn:org.openhab.osgiify/org.graalvm.truffle.truffle-api/25.0.1
-               mvn:org.openhab.osgiify/org.graalvm.truffle.truffle-compiler/25.0.1
-               mvn:org.openhab.osgiify/org.graalvm.truffle.truffle-runtime/25.0.1
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.js.js-language-25.1.0-SNAPSHOT.jar
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.js.js-scriptengine-25.1.0-SNAPSHOT.jar
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.regex.regex-25.1.0-SNAPSHOT.jar
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.polyglot.polyglot-25.1.0-SNAPSHOT.jar
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.sdk.collections-25.1.0-SNAPSHOT.jar
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.sdk.jniutils-25.1.0-SNAPSHOT.jar
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.sdk.nativeimage-25.1.0-SNAPSHOT.jar
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.sdk.word-25.1.0-SNAPSHOT.jar
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.shadowed.icu4j-25.1.0-SNAPSHOT.jar
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.shadowed.xz-25.1.0-SNAPSHOT.jar
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.truffle.truffle-api-25.1.0-SNAPSHOT.jar
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.truffle.truffle-compiler-25.1.0-SNAPSHOT.jar
+               https://bill.welliver.org/dist/openhab/graalvm-fixes/org.graalvm.truffle.truffle-runtime-25.1.0-SNAPSHOT.jar
                mvn:org.openhab.addons.bundles/org.openhab.automation.jsscripting/${project.version}
        
 


8. Change directories to bundles/org.openhab.automation.jsscripting and run:

mvn clean spotless:apply package

If all goes well, you should have a jar in the target directory that looks something like this:

target/org.openhab.automation.jsscripting-5.1.3.jar


This is the jar that you can drop into your addons/ directory, and which _should_ work for you, once we’ve installed the OSGI bundles it needs (see the next step).

Here’s the list of bundles we generated:

find . -name org.graalvm\*-SNAPSHOT.jar


You’ll need to put those somewhere your openhab install can get them: a local filesystem, on a web server somewhere (especially if the goal is to have multiple people use them).

Then, in your openhab console, install the bundles and set their load priority as needed to get things to install. There’s a note about this in the README of the openhab-osgiify project. You can also compare the bundle:list output of a system that has a working scripting system.

bundle:install file:///pathto/org.graalvm.js.js-language-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.js.js-scriptengine-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.llvm.llvm-api-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.polyglot.polyglot-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.python.python-language-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.python.python-resources-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.regex.regex-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.sdk.collections-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.sdk.jniutils-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.sdk.nativeimage-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.sdk.word-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.shadowed.icu4j-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.shadowed.json-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.shadowed.xz-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.tools.chromeinspector-tool-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.tools.profiler-tool-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.truffle.truffle-api-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.truffle.truffle-compiler-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.truffle.truffle-nfi-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.truffle.truffle-nfi-libffi-25.1.0-SNAPSHOT.jar
bundle:install file:///pathto/org.graalvm.truffle.truffle-runtime-25.1.0-SNAPSHOT.jar


  

Then, you’ll need to find the bundle id of truffle-api, tregex and js-language by using the bundle:list command. Make a note of the ids on your system and then run the following:



bundle:start-level TRUFFLE_API_ID 79
bundle:start-level TREGEX_ID 78
bundle:start-level JS_LANGUAGE_ID 78


>Once that’s done, you _should_ be able to start the JS Scripting add-on by finding it’s bundle Id and then running



bundle:start JS_SCRIPTING_ID


You’ll probably get a warning about being on an unsupported platform, which is actually a good thing, because it means things are working.



Your bundle list will look something like this:



269 │ Active   │  75 │ 5.1.3                 │ openHAB Add-ons :: Bundles :: Transformation Service :: RegEx
271 │ Active   │  78 │ 25.1.0.SNAPSHOT       │ GraalVM :: JS :: Language
272 │ Active   │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: JS :: Script Engine
273 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: LLVM :: API
274 │ Active   │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: Polyglot :: Polyglot
275 │ Resolved │  78 │ 25.1.0.SNAPSHOT       │ GraalVM :: Python :: Language
276 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: Python :: Resources
277 │ Resolved │  78 │ 25.1.0.SNAPSHOT       │ GraalVM :: Regex :: TRegex
278 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: SDK :: Collections
279 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: SDK :: JNI Utils
280 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: SDK :: Native Image
281 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: Truffle :: ICU4J
282 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: Truffle :: JSON
283 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: Truffle :: XZ
284 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: Tools :: Chrome Inspector
285 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: Tools :: Profiler
286 │ Active   │  79 │ 25.1.0.SNAPSHOT       │ GraalVM :: Truffle :: API
287 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: Truffle :: Compiler
288 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: Truffle :: NFI
289 │ Active   │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: Truffle :: NFI :: LibFFI
290 │ Active   │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: Truffle :: Runtime
291 │ Resolved │  80 │ 25.1.0.SNAPSHOT       │ GraalVM :: SDK :: Word
292 │ Active   │  80 │ 5.1.3                 │ openHAB Add-ons :: Bundles :: Automation :: JavaScript Scripting





>It seems like the script/rule editors won’t compile scripts without the Regexp add-on installed, so you’ll need to add that, as well (this add-on seems to provide access to a regex language through GraalVM’s Truffle framework)



>Once that’s done, you should be able to create a script and execute it. Hello world might be:



console.log(“Hello, world!”)


>Note that there are features requiring native platform support that openHAB could choose to start using at any point, and then we’d be back to this problem, with perhaps a more complicated fix, as then native platform support would need to be implemented. It’s not clear what that involves, I suspect a lot of the pieces are already there (processor, binary format, ffi interface, etc), but just gated by checks like “is Linux?”. 



>Also note that I haven’t attempted to automate the install/setup of the bundles. The information about what the dependencies are as well as their start order is in src/main/feature/feature.xml, but it isn’t being picked up in the resulting jar. There’s probably an easier way to go about it, but I’m not sure offhand what that is. Happy to hear suggestions about it.



>I’ve uploaded a snapshot of the 5.1.3 js scripting add-on, plus the dependencies it’s built on here:



>https://bill.welliver.org/dist/openhab/graalvm-fixes



>That should save you from at building the osgi bundles and add-on. The bundle dependency installation is still something you’ll need to perform yourself. Good luck, and if there’s anything I can do to help, please let me know.





 

Not categorized | RSS Feed | BackLinks

comments powered by Disqus