oracle / graaljs

A ECMAScript 2023 compliant JavaScript implementation built on GraalVM. With polyglot language interoperability support. Running Node.js applications!
Universal Permissive License v1.0
1.77k stars 188 forks source link

Context builder doesn't work with Payara server #409

Open rosshkaa opened 3 years ago

rosshkaa commented 3 years ago

Hello. I'm writing simple JS executor using GraalVM(20.3.0 (build 11.0.9+10-jvmci-20.3-b06)), Maven (3.6.3) and Payara server (5.2020.7) and got a trouble during context building.

The following ejb deploy fails with java.lang.IllegalStateException: No language and polyglot implementation was found on the classpath. Make sure the truffle-api.jar is on the classpath.:

@Startup
@Singleton
public class DemoScriptBean {

    @PostConstruct
    void init() {
         Context.newBuilder("js").allowAllAccess(true).build()
    }
}

Libraries graal-sdk, js, js-scriptengine and truffle-api are included as plain maven dependencies, e.g:

<properties>
        <graalvm.version>20.3.0</graalvm.version>
</properties>
...
 <dependency>
        <groupId>org.graalvm.truffle</groupId> 
        <artifactId>truffle-api</artifactId>
        <version>${graalvm.version}</version>
</dependency>

I've tried adding those libraries to Payara's lib as jars but it fails with:

Failed to install file:/E:/payara/glassfish/modules/graal-sdk-20.3.0.jar.
org.osgi.framework.BundleException: Could not create bundle object.
        at org.apache.felix.framework.Felix.installBundle(Felix.java:3312)
        at org.apache.felix.framework.BundleContextImpl.installBundle(BundleContextImpl.java:147)
        at com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner.install(BundleProvisioner.java:448)
        at com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner.installBundles(BundleProvisioner.java:208)
        at com.sun.enterprise.glassfish.bootstrap.osgi.OSGiGlassFishRuntimeBuilder.build(OSGiGlassFishRuntimeBuilder.java:142)
        at org.glassfish.embeddable.GlassFishRuntime._bootstrap(GlassFishRuntime.java:157)
        at org.glassfish.embeddable.GlassFishRuntime.bootstrap(GlassFishRuntime.java:110)
        at com.sun.enterprise.glassfish.bootstrap.GlassFishMain$Launcher.launch(GlassFishMain.java:124)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at com.sun.enterprise.glassfish.bootstrap.GlassFishMain.main(GlassFishMain.java:109)
        at com.sun.enterprise.glassfish.bootstrap.ASMain.main(ASMain.java:54)
Caused by: java.io.FileNotFoundException: META-INF/MANIFEST.MF
        at org.apache.felix.framework.util.Util.getMultiReleaseAwareManifestHeaders(Util.java:996)
        at org.apache.felix.framework.BundleImpl.createRevision(BundleImpl.java:1266)
        at org.apache.felix.framework.BundleImpl.<init>(BundleImpl.java:113)
        at org.apache.felix.framework.Felix.installBundle(Felix.java:3260)
        ... 13 more

The same code works just fine in standalone app.

wirthi commented 3 years ago

Hi @rosshkaa,

I cannot really help you with your question in detail, lacking experience with OSGi, ejb, and payara.

We do have documentation on how to run on Stock JDK though, see:

The IllegalStateException basically means that the truffle-api.jar (and potentially, the graaljs.jar and others) could not be found - they might not be provided in your setup at all, or they were hidden by a different ClassLoader.

When you say it works in a standalone app: what is different in the Payara setup you are trying? Are the classes moved to an uber-jar or similar?

Best, Christian

ja7 commented 3 years ago

Got a similar problem trying to integrate GraalJS into existing JavaEE 8 Applications Running on Payara 5.25.0 ( The Enterprice version ) and graalvm version GraalVM CE 21.0.0.2 (build 11.0.10+8-jvmci-21.0-b06).

DBC Created a simplified test application at https://github.com/DBCDK/payara-graalvm-js Works without problems with graalvm-ce-java8-21.0.0.2. but fails with graalvm-java11-21.0.0.2

With and without GraalJS .jars explicit on the war classpath. So suspects some part of the java11 Module system is doing funny stuff.

It also failed with the following jars on the war lib class path. WEB-INF/lib/compiler-21.0.0.2.jar WEB-INF/lib/graal-sdk-21.0.0.2.jar WEB-INF/lib/icu4j-67.1.jar WEB-INF/lib/js-21.0.0.2.jar WEB-INF/lib/js-launcher-21.0.0.2.jar WEB-INF/lib/js-scriptengine-21.0.0.2.jar WEB-INF/lib/launcher-common-21.0.0.2.jar WEB-INF/lib/regex-21.0.0.2.jar WEB-INF/lib/truffle-api-21.0.0.2.jar

The list is extracted with ((URLClassLoader) this.getClass().getClassLoader()).getURLs() in then same context as Context.newBuilder().allowExperimentalOptions(true).build()