Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native-image] Naitve-image tool does not recognize jar files that contain shell headers #405

Closed
Glavo opened this issue May 5, 2018 · 11 comments

Comments

@Glavo
Copy link

Glavo commented May 5, 2018

Jar files generated using this tricks can be run directly by java commands:

glavo@glavo:~/文档/Test$ java -jar amm.jar 
Loading...
Welcome to the Ammonite Repl 1.1.0
(Scala 2.12.4 Java 1.8.0_161)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ 

but the native-image tool doesn't recognize it:

glavo@glavo:~/文档/Test$ native-image -jar amm.jar 
Error: Given file does not appear to be a jar-file: /home/windows/Users/Glavo/Documents/Test/amm.jar
Caused by: java.io.IOException: No central table
@olpaw
Copy link
Member

olpaw commented May 7, 2018

@Glavo, thanks for your report. I will have a look if this can be fixed easily.

@olpaw
Copy link
Member

olpaw commented May 8, 2018

Fixed on master (023d1b0).
Note that doesn't mean building an image for Ammonite succeeds.
IIUC, Ammonite is a full Scala repl relying on dynamic classloading. SubstrateVM doesn't support dynamic classloading: https://github.com/oracle/graal/blob/master/substratevm/LIMITATIONS.md#dynamic-class-loading--unloading

@olpaw olpaw closed this as completed May 8, 2018
@olpaw
Copy link
Member

olpaw commented May 8, 2018

FWIW, implementing a full Scala repl on top of SubstrateVM would require a truffle-language implementation for Scala.
(I wonder if anyone from the Scala community is considering truffle as an execution environment for
https://github.com/lampepfl/dotty/tree/master/compiler/src/dotty/tools/dotc/core/tasty)

@avatar21
Copy link

avatar21 commented Jun 6, 2018

I had the same problem ... trying to convert a maven-based springboot jar into executable.

Error: Given file does not appear to be a jar-file: /home/me/note-service-provider-1.0.0.jar
Caused by: java.io.IOException: No central table

I saw that you have fix it in here, I assume now it should parse jar correctly, so I checkout from git, how am I going to build the latest changes that you've made, but I seems not able to follow those instructions (specifically SubstrateVM native-image binary), I find it not straight forward enough.

I'm following this guide:
Here I illustrate what I've done ...

# from my home path
> cd ~/
# pull the mx code base
> git clone https://github.com/graalvm/mx.git
# setting env. variable
> export PATH=~/mx:$PATH
# pull the graal code base
> git clone https://github.com/graalvm/graal.git
> cd graal/compiler
# install missing dependency for my Ubuntu 16.04 (Bash on Ubuntu on Windows)
> sudo apt-get install build-essential
> sudo apt-get install python-minimal
# ... etc I don't want to bore you all
# setting env variable for JDK (the lab jvmci version)
> export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_171
> export PATH=$PATH:$JAVA_HOME/bin:
# test if java correctly
> java -version
# to test if env config correctly for mx
> mx
# build graal compiler
> mx build
# try the graal vm
> mx vm
# execute correctly

Things are ok now, how do I proceed from here ... ?? Any help is much appreciated.

@cstancu
Copy link
Member

cstancu commented Jun 6, 2018

@avatar21 to build SubstrateVM from source please follow the instructions here.

@avatar21
Copy link

avatar21 commented Jun 6, 2018

Erm I kinda get it one step further this time, it generates a binary for me ... super NICE, however the result isn't correct (exception thrown), probably related to the UnsupportedElementsAtRuntime previously ...

  • generate executable from jar (1st attempt)
> mx native-image -jar note-service-provider-1.0.0.jar
   classlist:   2,931.71 ms
       (cap):   4,954.04 ms
       setup:   6,557.64 ms
    analysis:   9,750.60 ms
error: unsupported features in 2 methods
Detailed message:
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Unsupported field java.net.URL.handlers is reachable
To diagnose the issue, you can add the option -H:+ReportUnsupportedElementsAtRuntime. The unsupported element is then reported at run time when it is accessed the first time.
Trace:
        at parsing java.net.URL.setURLStreamHandlerFactory(URL.java:1118)
Call path from entry point to java.net.URL.setURLStreamHandlerFactory(URLStreamHandlerFactory):
        at java.net.URL.setURLStreamHandlerFactory(URL.java:1110)
        at org.springframework.boot.loader.jar.JarFile.resetCachedUrlHandlers(JarFile.java:392)
        at org.springframework.boot.loader.jar.JarFile.registerUrlProtocolHandler(JarFile.java:382)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:48)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
        at com.oracle.svm.reflect.proxies.Proxy_1_JarLauncher_main.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:173)
        at com.oracle.svm.core.code.CEntryPointCallStubs.com_002eoracle_002esvm_002ecore_002eJavaMainWrapper_002erun_0028int_002corg_002egraalvm_002enativeimage_002ec_002etype_002eCCharPointerPointer_0029(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Unsupported method java.security.ProtectionDomain.getCodeSource() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
To diagnose the issue, you can add the option -H:+ReportUnsupportedElementsAtRuntime. The unsupported element is then reported at run time when it is accessed the first time.
Trace:
        at parsing org.springframework.boot.loader.Launcher.createArchive(Launcher.java:118)
Call path from entry point to org.springframework.boot.loader.Launcher.createArchive():
        at org.springframework.boot.loader.Launcher.createArchive(Launcher.java:117)
        at org.springframework.boot.loader.ExecutableArchiveLauncher.<init>(ExecutableArchiveLauncher.java:38)
        at org.springframework.boot.loader.JarLauncher.<init>(JarLauncher.java:35)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
        at com.oracle.svm.reflect.proxies.Proxy_1_JarLauncher_main.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:173)
        at com.oracle.svm.core.code.CEntryPointCallStubs.com_002eoracle_002esvm_002ecore_002eJavaMainWrapper_002erun_0028int_002corg_002egraalvm_002enativeimage_002ec_002etype_002eCCharPointerPointer_0029(generated:0)

Error: Image building with exit status 1
  • generate executable from jar (2nd attempt)
# generate executable from jar
> mx native-image -H:+ReportUnsupportedElementsAtRuntime -jar note-service-provider-1.0.0.jar
   classlist:   2,408.50 ms
       (cap):   4,617.50 ms
       setup:   6,250.30 ms
  (typeflow):   8,559.16 ms
   (objects):   3,821.70 ms
  (features):      70.76 ms
    analysis:  14,103.34 ms
    universe:     426.30 ms
     (parse):   2,621.82 ms
    (inline):   1,908.81 ms
   (compile):  14,249.76 ms
     compile:  19,520.11 ms
       image:   2,073.85 ms
       write:     941.29 ms
     [total]:  45,856.95 ms
  • try to execute
# rename it to something simpler
> mv note-service-provider-1.0.0 note-service-provider
# execution
> ./note-service-provider
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.lang.Throwable.<init>(Throwable.java:310)
        at java.lang.Exception.<init>(Exception.java:102)
        at java.lang.ReflectiveOperationException.<init>(ReflectiveOperationException.java:89)
        at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:72)
        at com.oracle.svm.reflect.proxies.Proxy_1_JarLauncher_main.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:173)
Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: Unsupported constructor java.security.ProtectionDomain.<init>(CodeSource, PermissionCollection) is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
        at java.lang.Throwable.<init>(Throwable.java:265)
        at java.lang.Error.<init>(Error.java:70)
        at com.oracle.svm.core.jdk.UnsupportedFeatureError.<init>(UnsupportedFeatureError.java:31)
        at com.oracle.svm.core.jdk.Target_com_oracle_svm_core_util_VMError.unsupportedFeature(VMErrorSubstitutions.java:100)
        at java.security.ProtectionDomain.<init>(ProtectionDomain.java:143)
        at com.oracle.svm.core.hub.DynamicHub.getProtectionDomain(DynamicHub.java:941)
        at org.springframework.boot.loader.Launcher.createArchive(Launcher.java:117)
        at org.springframework.boot.loader.ExecutableArchiveLauncher.<init>(ExecutableArchiveLauncher.java:40)
        at org.springframework.boot.loader.JarLauncher.<init>(JarLauncher.java:35)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
        ... 3 more

@cstancu
Copy link
Member

cstancu commented Jun 6, 2018

@avatar21 yes, that error means that we don't currently support java.security.ProtectionDomain.

@avatar21
Copy link

avatar21 commented Jun 6, 2018

@cstancu thanks, is it in another word SpringBoot is not supported yet??

@fujohnwang
Copy link

block on this ProtectionDomain too

@cstancu
Copy link
Member

cstancu commented Aug 8, 2018

@fujohnwang you can follow the progress of that bug here #564. It will be fixed soon.

@fujohnwang
Copy link

@cstancu got it, thanks

zakkak pushed a commit to zakkak/mandrel that referenced this issue Sep 21, 2022
Add workflow additions for uploading build stats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants