Repository navigation
Closed
Labels
Description
I'm trying to compile a 'simple' spring-boot web project to native image.
Project source:
https://drive.google.com/file/d/136E00Gux6vL3tvcZFM3KgcNuIvtXWlj1/view?usp=sharing
Command:
native-image -jar graal-0.0.1-SNAPSHOT.jar
Log:
Build on Server(pid: 25018, port: 26682)*
classlist: 1,200.03 ms
(cap): 1,115.73 ms
setup: 2,508.68 ms
analysis: 8,853.48 ms
error: unsupported features in 3 methods
Detailed message:
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Unsupported constructor java.lang.ClassLoader.<init>(ClassLoader) 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 java.security.SecureClassLoader.<init>(SecureClassLoader.java:76)
Call path from entry point to java.security.SecureClassLoader.<init>(ClassLoader):
at java.security.SecureClassLoader.<init>(SecureClassLoader.java:76)
at java.net.URLClassLoader.<init>(URLClassLoader.java:100)
at org.springframework.boot.loader.LaunchedURLClassLoader.<init>(LaunchedURLClassLoader.java:50)
at org.springframework.boot.loader.Launcher.createClassLoader(Launcher.java:74)
at org.springframework.boot.loader.Launcher.createClassLoader(Launcher.java:64)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:49)
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:199)
at Lcom/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 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:199)
at Lcom/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:199)
at Lcom/oracle/svm/core/code/CEntryPointCallStubs;.com_002eoracle_002esvm_002ecore_002eJavaMainWrapper_002erun_0028int_002corg_002egraalvm_002enativeimage_002ec_002etype_002eCCharPointerPointer_0029(generated:0)
Error: Processing image build request failed
Reacted by Philippe Soares, ezomode, Luiz Eduardo Kowalski, Danilo Gomes, Markus Schulte, Armel Soro, forseti, Hemantkumar Chigadani, costincaraivan, Jorge Tovar and 1 more
Activity
cstancu commentedon Apr 20, 2018
Thank you for your report. Spring-boot uses dynamic class loading which is a limitation of SubstrateVM. Sometimes it is possible to avoid dynamic class loading (which might reduce some functionality). I will look into this possibility for spring-boot.
dsyer commentedon May 11, 2018
You can get past this specific error by not using the fat jar launcher as a main method. But there are other bogies lurking. Spring Boot has a static (but optional) dependency on Groovy, for example, so even though it will never be used at runtime, a native-image cannot be built because
groovy.lang.Closureis not available for a vanilla app. If you add Groovy to the classpath (even though it will not be used) you can get past that, but the build fails again because of ajava.lang.ClassCastException: jdk.vm.ci.hotspot.HotSpotUnresolvedJavaType cannot be cast to jdk.vm.ci.meta.ResolvedJavaType. I managed to build a binary image by creating a dummy, empty interface calledgroovy.lang.Closureand putting that on the classpath instead of the real groovy. Then the image fails at runtime because of an issue withjava.lang.reflect.Proxy(I'll open a separate ticket about that because it might be interesting on its own).cstancu commentedon May 12, 2018
@dsyer can you provide the trace for the
java.lang.ClassCastException: jdk.vm.ci.hotspot.HotSpotUnresolvedJavaType cannot be cast to jdk.vm.ci.meta.ResolvedJavaTypethat you mention above? Thank you!dsyer commentedon May 12, 2018
Sure:
tdanylchuk commentedon Jun 29, 2018
is there any other workaround for building native-image for spring boot app, or for now it's blocked w\o any hopes?
dsyer commentedon Jun 29, 2018
There's no way yet to run a Spring Boot application. Not even the
GenericConversionServicefrom spring-core will work in a native image right now I think, so that's a blocker for a large class of Spring applications (not just Spring Boot). The Graal team have said they are interested in making it work though, so I wouldn't say there is no hope, but certainly it is blocked on this and other issues.tdanylchuk commentedon Jun 29, 2018
Well, GraalVM looks promising for microservices world, since services are getting fat and start time is increasing, which breaks one of the microservices paradigm - fast startup.
Since most of the microsevices in java are build upon Spring Boot it's crucial to have possibility to build native image from it.
I would like to use/test as soon issues with spring will be resolved.
Can we make this issue/thread main for spring/boot? :D
Looking forward! Thanks!
sdeleuze commentedon Jul 2, 2018
See #507 about the
ConversionServiceissue.sdeleuze commentedon Jul 2, 2018
I have created SPR-16991 to track SubstrateVM Spring support status.
adamsiemion commentedon Jul 2, 2018
More than a week ago Josh Long at the beginning of his Devoxx (devoxx.pl) talk demoed a Spring Boot/Fu app built as a native image using GraalVM: spring-attic/spring-fu#29
dsyer commentedon Jul 3, 2018
@joshlong used the Kotlin sample app from here: spring-attic/spring-fu#29. There's another minimal Spring app in Java here that works: https://github.com/dsyer/spring-boot-micro-apps (see the instructions in the README). Neither of those apps uses Spring Boot.
cstancu commentedon Mar 14, 2019
The originally reported issue has been fixed. With the latest release, you can build an image using
native-image --report-unsupported-elements-at-runtime -jar build/libs/graal-0.0.1-SNAPSHOT.jar. However, running the image I get:It looks like the example app tries to execute a jar which is currently not supported with
native-image.