graal-js-jdk11-maven-demo icon indicating copy to clipboard operation
graal-js-jdk11-maven-demo copied to clipboard

Maven example with standalone jar

Open dschow opened this issue 6 years ago • 4 comments

I'm wondering if it's possible to information on how to include the dependencies required to run this sample with a standalone jar.

dschow avatar Feb 02 '19 09:02 dschow

If what you want to achieve is to have one single jar you can run, that's not really possible if you want to have compilation enabled with graal, since you need to update the module path.

boris-spas avatar Mar 20 '19 10:03 boris-spas

Very curious about this, too. Why can exec-maven-plugin do what we cannot do with java -jar ?

Taking this project as an example, mvn -X exec:exec shows:

[DEBUG] Executing command line: [/Users/averes/.jabba/jdk/[email protected]/Contents/Home/bin/java, @target/modulepath, 
-classpath, /Users/averes/dev/graal-js-jdk11-maven-demo/target/classes:/Users/averes/.m2/repository/org/graalvm/sdk/graal-sdk/19.3.1/graal-sdk-19.3.1.jar:/Users/averes/.m2/repository/org/graalvm/js/js/19.3.1/js-19.3.1.jar:/Users/averes/.m2/repository/org/graalvm/regex/regex/19.3.1/regex-19.3.1.jar:/Users/averes/.m2/repository/org/graalvm/truffle/truffle-api/19.3.1/truffle-api-19.3.1.jar:/Users/averes/.m2/repository/org/ow2/asm/asm/7.1/asm-7.1.jar:/Users/averes/.m2/repository/org/ow2/asm/asm-tree/7.1/asm-tree-7.1.jar:/Users/averes/.m2/repository/org/ow2/asm/asm-analysis/7.1/asm-analysis-7.1.jar:/Users/averes/.m2/repository/org/ow2/asm/asm-commons/7.1/asm-commons-7.1.jar:/Users/averes/.m2/repository/org/ow2/asm/asm-util/7.1/asm-util-7.1.jar:/Users/averes/.m2/repository/com/ibm/icu/icu4j/64.2/icu4j-64.2.jar:/Users/averes/.m2/repository/org/graalvm/js/js-scriptengine/19.3.1/js-scriptengine-19.3.1.jar:/Users/averes/.m2/repository/org/graalvm/tools/profiler/19.3.1/profiler-19.3.1.jar:/Users/averes/.m2/repository/org/graalvm/tools/chromeinspector/19.3.1/chromeinspector-19.3.1.jar, 
-XX:+UnlockExperimentalVMOptions, 
-XX:+EnableJVMCI, 
--upgrade-module-path=/Users/averes/dev/graal-js-jdk11-maven-demo/target/compiler/compiler.jar, com.mycompany.app.App]

So why can't I do

java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI --upgrade-module-path=/Users/averes/dev/graal-js-jdk11-maven-demo/target/compiler/compiler.jar -jar target/my-app-1.0-SNAPSHOT.jar

Error occurred during initialization of boot layer
java.lang.module.FindException: Module org.graalvm.truffle not found, required by jdk.internal.vm.compiler

Or (basically identical to the maven exec):

java @target/modulepath -classpath /Users/averes/dev/graal-js-jdk11-maven-demo/target/classes:/Users/averes/.m2/repository/org/graalvm/sdk/graal-sdk/19.3.1/graal-sdk-19.3.1.jar:/Users/averes/.m2/repository/org/graalvm/js/js/19.3.1/js-19.3.1.jar:/Users/averes/.m2/repository/org/graalvm/regex/regex/19.3.1/regex-19.3.1.jar:/Users/averes/.m2/repository/org/graalvm/truffle/truffle-api/19.3.1/truffle-api-19.3.1.jar:/Users/averes/.m2/repository/org/ow2/asm/asm/7.1/asm-7.1.jar:/Users/averes/.m2/repository/org/ow2/asm/asm-tree/7.1/asm-tree-7.1.jar:/Users/averes/.m2/repository/org/ow2/asm/asm-analysis/7.1/asm-analysis-7.1.jar:/Users/averes/.m2/repository/org/ow2/asm/asm-commons/7.1/asm-commons-7.1.jar:/Users/averes/.m2/repository/org/ow2/asm/asm-util/7.1/asm-util-7.1.jar:/Users/averes/.m2/repository/com/ibm/icu/icu4j/64.2/icu4j-64.2.jar:/Users/averes/.m2/repository/org/graalvm/js/js-scriptengine/19.3.1/js-scriptengine-19.3.1.jar:/Users/averes/.m2/repository/org/graalvm/tools/profiler/19.3.1/profiler-19.3.1.jar:/Users/averes/.m2/repository/org/graalvm/tools/chromeinspector/19.3.1/chromeinspector-19.3.1.jar -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI --upgrade-module-path=/Users/averes/dev/graal-js-jdk11-maven-demo/target/compiler/compiler.jar -jar target/my-app-1.0-SNAPSHOT.jar
no main manifest attribute, in target/my-app-1.0-SNAPSHOT.jar

Is there something simple I am missing? Thank you!

adveres avatar Jan 31 '20 20:01 adveres

I'm not quite sure what you are asking but I'll take a crack and answering what I think you are asking so please let me know if I'm missing the mark.

The first example you gave cannot work since target/my-app-1.0-SNAPSHOT.jar does not contain any of the dependencies. If you managed to build a correct fat jar (including all the dependencies and ensuring the module path is correctly set up) than you may be able to do this.

The problem with your second example (also with the first one) is that the built jar does not have a proper manifest to be executed with -jar (https://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute)

boris-spas avatar Feb 03 '20 09:02 boris-spas

Thank you for checking in!

Let me add some clarity for my use-case. I'm trying to run a fat Spring Boot JAR in Docker, which can run some JavaScript too. Today java is OpenJDK 11.0.2.

CMD java -jar /opt/foo/mySpringBoot.jar

I did end up getting a new stacktrace when I used Context instead of ScriptEngine, which appears to be this issue: https://github.com/oracle/graal/issues/1348

So perhaps I just need to wait for the next release.

Example + trace

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        try(Context context = Context.newBuilder("js").build()) {
            context.eval("js", "print('Hello from JS!');");
        }

        SpringApplication.run(Application.class, args);
    }
Exception in thread "main" java.lang.reflect.InvocationTargetException
	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 org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Caused by: java.nio.file.FileSystemNotFoundException
	at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:169)
	at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:155)
	at java.base/java.nio.file.Path.of(Path.java:208)
	at java.base/java.nio.file.Paths.get(Paths.java:97)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.LanguageCache$Loader.getLanguageHomeFromURLConnection(LanguageCache.java:546)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.LanguageCache$Loader$ServicesLoader.loadImpl(LanguageCache.java:827)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.LanguageCache$Loader.load(LanguageCache.java:490)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.LanguageCache.createLanguages(LanguageCache.java:205)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.LanguageCache.loadLanguages(LanguageCache.java:195)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.LanguageCache.languages(LanguageCache.java:185)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.initializeLanguages(PolyglotEngineImpl.java:647)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.<init>(PolyglotEngineImpl.java:205)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.<init>(PolyglotEngineImpl.java:186)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotImpl.buildEngine(PolyglotImpl.java:195)
	at org.graalvm.sdk/org.graalvm.polyglot.Engine$Builder.build(Engine.java:506)
	at org.graalvm.sdk/org.graalvm.polyglot.Context$Builder.build(Context.java:1444)
	at net.myspring.server.Application.main(Application.java:34)
	... 8 more

adveres avatar Feb 03 '20 16:02 adveres