3 ms·
I'm happy with language interoperability as a concept but how can i mix java and js in the same codebase with graalvm? And would it make sense? What are the adv
by andretti1977 6y ago
I'm happy with language interoperability as a concept but how can i mix java and js in the same codebase with graalvm? And would it make sense? What are the advantages of this approach?
- fniephaus 6y agoCurrently, you'd use the polyglot package that ships with the GraalVM SDK: https://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/Context.html https://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/Con... Here are a couple of demos: https://github.com/graalvm/graalvm-demos https://github.com/graalvm/graalvm-demos I said "currently", because you currently have to use the host Java, that is the Java on top of which all other languages are implemented. The GraalVM team is working on Project Espresso, a Java written in Truffle. That will make polyglot programming with Java much more consistent with the rest of the languages. Project Espresso isn't public yet, but here's the latest update from the team working on it: https://github.com/oracle/graal/issues/1656#issuecomment-664335618 https://github.com/oracle/graal/issues/1656#issuecomment-664...
- jbister 6y agoYou can use it for doing server side rendering of React or other JS framework components. I have a VERY rough repository[0] where I tested this out a while back. The way I did it was to export functions on the global object in JS[1] which could then easily be called from Java code[2]. I'm sure there's a better way to accomplish the same thing. What I found interesting with this approach is that it allows you to do server side rendering without needing a separate server and without needing any third party dependencies aside from GraalVM itself. 0. https://github.com/JackBister/javalin-preact-archetype https://github.com/JackBister/javalin-preact-archetype 1. https://github.com/JackBister/javalin-preact-archetype/blob/master/src/main/resources/archetype-resources/src/main/resources/frontend/src/server.ts https://github.com/JackBister/javalin-preact-archetype/blob/... 2. https://github.com/JackBister/javalin-preact-archetype/blob/master/src/main/resources/archetype-resources/src/main/java/BundledServerSideRenderer.java#L23 https://github.com/JackBister/javalin-preact-archetype/blob/...