flow: Hilla app with @PWA annotation fails when running as native compiled image on macOS

Describe the bug

A Hilla app with @PWA annotation throws an exception when running as native compiled image:

java.lang.UnsatisfiedLinkError: No awt in java.library.path
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryRelative(NativeLibrarySupport.java:136) ~[na:na]

Expected-behavior

A Hilla app with @PWA annotation should not throw unexpected exceptions when running as native compiled image.

Reproduction

Create a new Hilla project:

npx @hilla/cli@latest init --next hilla-native-pwa

Add @PWA(name = "Hilla PWA", shortName = "PWA") to src/main/java/com/example/application/Application.java.

Compile Hilla app to native image:

./mvnw clean package -Pproduction -Pnative native:compile

Run Hilla app as native compiled image:

./target/hilla-native-pwa

System Info

Hilla: 24.4.0.beta5 Hilla CLI: 2.0.1 Java: 21.0.2 (OpenJDK Runtime Environment GraalVM CE 21.0.2+13.1 - build 21.0.2+13-jvmci-23.1-b30) OS: macOS Sonoma 14.4.1 (23E224)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Would the correct fix here be to produce the images at production build time and not have a dependency on awt?

Yes, you are right 😄 There are a couple of library files (.so) in the target directory of the project, after I did ./mvnw clean package -Pproduction -Pnative native:compile. If I change my Dockerfile to copy those library files…

FROM debian:bookworm-slim

WORKDIR /app

COPY target/*.so /app/
COPY target/hilla-native-pwa /app/hilla-native-pwa

CMD ["/app/hilla-native-pwa"]

… everything works fine! The Docker image is created as desired and when I start a Docker container from that image I can access the Hilla PWA without errors 🙌

Thanks for testing. I’ll change a bit the title to mention MacOS and transfer the issue to the flow repo for further investigation.

I tested with GraalVM CE 21 and 22, and the native executable works fine with both. No errors at runtime and the application is working. I’m on Linux, I don’t know if that makes a difference.

That’s weird. I tried it and it worked for me

Also, if you are want to build flow locally but use Vaadin platform 24.4, maybe better build from the 24.4 branch instead of main

BTW, there should also be a first alpha for Vaadin 24.5 that you can try without having to build flow locally

The fix is in the vaadin-spring artifact

vaadin/flow#19457 should fix the issue, but it is not yet released. You can try it out with 24.4-SNAPSHOT