helidon-io / helidon

Java libraries for writing microservices
https://helidon.io
Apache License 2.0
3.52k stars 564 forks source link

Cannot create native executable for application with JPA on Windows #5299

Closed szachmati closed 2 years ago

szachmati commented 2 years ago

Native executable build on Windows doesn't work with JPA

Environment Details


Problem Description

Hello, I created Helidon MP application for CRUD functionality using JPA 3.0 Jakarta integration with Hibernate. Everything works fine during standard building with helidon dev and mvn clean package. The problem occurs while trying to build application as a native executable using GraalVM.

Steps to reproduce:

  1. Application is available here https://github.com/szachmati/product-api/tree/master/helidon
  2. Run mvn clean package -DskipTests -Pnative-image command in x64 Native Tools Command Prompt(Windows)
  3. See logs

Output from Maven:

`[INFO] Copying slf4j-api-1.7.32.jar to E:\studia\WIT\sem4\magisterka\shop\helidon\target\libs\slf4j-api-1.7.32.jar
[INFO] Copying helidon-mp-graal-native-image-extension-3.0.2.jar to E:\studia\WIT\sem4\magisterka\shop\helidon\target\libs\helidon-mp-graal-native-image-extension-3.0.2.jar
[INFO] Copying helidon-graal-native-image-extension-3.0.2.jar to E:\studia\WIT\sem4\magisterka\shop\helidon\target\libs\helidon-graal-native-image-extension-3.0.2.jar
[INFO]
[INFO] --- helidon-maven-plugin:3.0.0:report (third-party-license-report) @ shop ---
[INFO] Scanning shop
[INFO] Reading input from HELIDON_THIRD_PARTY_LICENSES.xml on classpath
[INFO] Writing output to E:\studia\WIT\sem4\magisterka\shop\helidon\target\HELIDON_THIRD_PARTY_LICENSES.txt
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ shop ---
[INFO] Building jar: E:\studia\WIT\sem4\magisterka\shop\helidon\target\shop.jar
[INFO]
[INFO] --- helidon-maven-plugin:3.0.0:native-image (native-image) @ shop ---
[INFO] Building native image :E:\studia\WIT\sem4\magisterka\shop\helidon\target\shop
[WARNING] Warning: Ignoring server-mode native-image argument --no-server.
[WARNING] Warning: Using a deprecated option --allow-incomplete-classpath from 'META-INF\native-image\io.helidon.webserver\helidon-webserver\native-image.properties' in 'file:///E:/studia/WIT/sem4/magisterka/shop/helidon/target/libs/helidon-webserver-3.0.2.jar'. Allowing an incomplete classpath is now the default. Use --link-at-build-time to report linking errors at image build time for a class or package.
[WARNING] Warning: Option 'EnableAllSecurityServices' is deprecated and might be removed from future versions
[INFO] ========================================================================================================================
[INFO] GraalVM Native Image: Generating 'shop' (executable)...
[INFO] ========================================================================================================================
[WARNING] --initialize-at-build-time without arguments has been deprecated when not using --diagnostics-mode. With GraalVM 22.0.0 --initialize-at-build-time will only work with --diagnostics-mode for debugging purposes.
[WARNING] The reason for deprecation is that --initalize-at-build-time does not compose, i.e., a single library can make assumptions that the whole classpath can be safely initialized at build time; that assumption is often incorrect.
[INFO] 2022.11.01 23:33:25 INFO io.helidon.common.LogConfig Thread[main,5,main]: Logging at initialization configured using classpath: /logging.properties
[INFO] 2022.11.01 23:33:25 INFO org.hibernate.validator.internal.util.Version Thread[main,5,main]: HV000001: Hibernate Validator 7.0.2.Final
[INFO] Warning: Feature class io.helidon.integrations.graal.mp.nativeimage.extension.WeldFeature is annotated with the deprecated annotation @AutomaticFeature. Support for this annotation will be removed in a future version of GraalVM. Applications should register a feature using the option --features=io.helidon.integrations.graal.mp.nativeimage.extension.WeldFeature
[WARNING] Warning: Could not resolve org.hibernate.annotations.common.util.impl.Log_$logger for reflection configuration. Reason: java.lang.ClassNotFoundException: org.hibernate.annotations.common.util.impl.Log_$logger.
[WARNING] Warning: Could not resolve org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory for reflection configuration. Reason: java.lang.ClassNotFoundException: org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.
[WARNING] Warning: Could not resolve org.hibernate.jmx.internal.DisabledJmxServiceImpl for reflection configuration. Reason: java.lang.ClassNotFoundException: org.hibernate.jmx.internal.DisabledJmxServiceImpl.
[WARNING] Warning: Could not resolve org.hibernate.tool.hbm2ddl.SingleLineSqlCommandExtractor for reflection configuration. Reason: java.lang.ClassNotFoundException: org.hibernate.tool.hbm2ddl.SingleLineSqlCommandExtractor.
[WARNING] Warning: Could not resolve org.hibernate.tuple.entity.PojoEntityTuplizer for reflection configuration. Reason: java.lang.ClassNotFoundException: org.hibernate.tuple.entity.PojoEntityTuplizer.
[INFO] [1/7] Initializing...                                                                                   (23,2s @ 0,52GB)
[INFO]  Version info: 'GraalVM 22.3.0 Java 17 CE'
[INFO]  Java version info: '17.0.5+8-jvmci-22.3-b08'
[INFO]  C compiler: cl.exe (microsoft, x64, 19.33.31629)
[INFO]  Garbage collector: Serial GC
[INFO]  2 user-specific feature(s)
[INFO]  - io.helidon.integrations.graal.mp.nativeimage.extension.WeldFeature
[INFO]  - io.helidon.integrations.graal.nativeimage.extension.HelidonReflectionFeature
[INFO] 2022.11.01 23:33:37 WARNING io.helidon.common.HelidonFeatures Thread[main,5,main]: Feature 'Hibernate' for path 'JPA/Hibernate' has limited support in native image: Experimental support, tested on limited use cases
[INFO] 2022.11.01 23:33:37 WARNING io.helidon.common.HelidonFeatures Thread[main,5,main]: Feature 'JTA' for path 'JTA' has limited support in native image: Experimental support, tested on limited use cases
[INFO]
[WARNING] Fatal error: java.lang.IllegalAccessError: class io.helidon.integrations.graal.nativeimage.extension.HelidonReflectionFeature (in unnamed module @0x4116f66a) cannot access class com.oracle.svm.core.jdk.Resources (in module org.graalvm.nativeimage.builder) because module org.graalvm.nativeimage.builder does not export com.oracle.svm.core.jdk to unnamed module @0x4116f66a
[INFO] ------------------------------------------------------------------------------------------------------------------------
[WARNING]       at io.helidon.integrations.graal.nativeimage.extension.HelidonReflectionFeature.lambda$processEntity$32(HelidonReflectionFeature.java:283)
[WARNING]       at java.base/java.lang.Iterable.forEach(Iterable.java:75)
[INFO]                         0,8s (2,1% of total time) in 13 GCs | Peak RSS: 1,30GB | CPU load: 1,38
[WARNING]       at io.helidon.integrations.graal.nativeimage.extension.HelidonReflectionFeature.processEntity(HelidonReflectionFeature.java:279)
[INFO] ========================================================================================================================
[WARNING]       at io.helidon.integrations.graal.nativeimage.extension.HelidonReflectionFeature.beforeAnalysis(HelidonReflectionFeature.java:114)
[INFO] Failed generating 'shop' after 25,3s.
[WARNING]       at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$9(NativeImageGenerator.java:736)
[WARNING]       at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:85)
[WARNING]       at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:736)
[WARNING]       at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:578)
[WARNING]       at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)
[WARNING]       at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
[WARNING]       at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
[WARNING]       at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
[WARNING] Error: Image build request failed with exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  46.603 s
[INFO] Finished at: 2022-11-01T23:33:40+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.helidon.build-tools:helidon-maven-plugin:3.0.0:native-image (native-image) on project shop: Image generation failed, exit code: 1 -> [Help 1]
[ERROR]`

I also tried to build native executable with JPA for Helidon 2.5.4 from scratch(https://helidon.io/starter/2.5.4), but it didn't work for Hibernate and EclipseLink

Should this issue also be sent to GrallVM team? Regards

tomas-langer commented 2 years ago

Hello, Helidon 3 does not (yet) support GraalVM 22.3, please use 21.x We are now working on supporting it: https://github.com/helidon-io/helidon/pull/5308

There are multiple issues that you would encounter - one of them is the module accessibility, then we use --initialize-at-build-time by default.

To fix your problem, you can add --add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.configure=ALL-UNNAMED to native image arguments

tomas-langer commented 2 years ago

I will close this issue, as the version you use is not supported now. When we release next version of 3.x, 22.3.0 will be the minimal required version.

szachmati commented 2 years ago

Hi @tomas-langer sorry for so late response, I forgot to answer. In case someone else occurs such error here is workaround. mvn clean package -DskipTests and after creating jar file in target native-image -jar target/app.jar now it works 😄

Regards