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

Quarkus static image building with AWT #36026

Closed
antonwiens opened this issue Sep 20, 2023 · 5 comments
Closed

Quarkus static image building with AWT #36026

antonwiens opened this issue Sep 20, 2023 · 5 comments
Labels

Comments

@antonwiens
Copy link

antonwiens commented Sep 20, 2023

Description

Hello Quarkus Team,

i just migrated from Quarkus 2 to Quarkus 3 and have problems regarding AWT, as you may have seen from other issues i reported on the Quarkus AWT extension. But now i am a bit lost on the topic of static image building regarding AWT.
On Quarkus 2 a statically linked native image was easily built even using AWT and our service runs fine with it. But with the upgrade to Quarkus 3 and the new GRAALVM version, it seems that the static image is not statically linked against AWT anymore.

My statically linked native image with AWT Extension is building fine, but during runtime i get the following error:

Caused by: java.lang.UnsatisfiedLinkError: no awt in java.library.path
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryRelative(NativeLibrarySupport.java:136)
        at [email protected]/java.lang.ClassLoader.loadLibrary(ClassLoader.java:50)
        at [email protected]/java.lang.Runtime.loadLibrary0(Runtime.java:818)
        at [email protected]/java.lang.System.loadLibrary(System.java:1989)
        at [email protected]/java.awt.image.ColorModel$1.run(ColorModel.java:210)
        at [email protected]/java.awt.image.ColorModel$1.run(ColorModel.java:208)
        at [email protected]/java.security.AccessController.executePrivileged(AccessController.java:171)
        at [email protected]/java.security.AccessController.doPrivileged(AccessController.java:318)
        at [email protected]/java.awt.image.ColorModel.loadLibraries(ColorModel.java:207)
        at [email protected]/java.awt.image.ColorModel.<clinit>(ColorModel.java:220)
        at [email protected]/java.awt.image.Raster.<clinit>(Raster.java:172)
        ...

Since i dont know if this is a bug, my fault in doing something wrong or i have to do something else, i would really appreciate if you could add some documentation on the AWT extension regarding required .so or .dll files i have to put into the runtime container if i have an statically linked native image. Usually i have a scratch docker container where i put my application and it runs standalone with some config files. But now i don`t know what to exactly put in, to get it running again.

Could you please help me / add more documentation to it?

Implementation ideas

No response

@geoand
Copy link
Contributor

geoand commented Sep 20, 2023

cc @Karm

@antonwiens
Copy link
Author

Ok, i managed to get my backend service working with AWT and static image building without relying on quarkus AWT extension, as this was messing with the static image. I am not using visual awt features as i need awt only for pdfbox.

Thats what i did:

  • Removed quarkus-awt extension
  • add to build config: --initialize-at-run-time=sun.awt.X11,sun.awt.dnd,java.awt.event,com.apple.eawt,sun.awt.X11GraphicsConfig
  • add a class named io.quarkus.awt.runtime.JDKSubstitutions so that quarkus does not substitute the awt classes

Thats it, now PDFbox and awt work for me in the backend service to generate pdf files without relying on quarkus-awt.
I think this works because pdfbox is a special case in combination with static image compilation. But i am fine with it.
When building static, AWT seems to have less of a problem with relying on .so files and jni configuration.

@Karm
Copy link
Member

Karm commented Oct 3, 2023

Hello @antonwiens, the problem with not doing things in https://github.com/quarkusio/quarkus/blob/main/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java is that it could blow up at runtime if you deal with unexpected data that, e.g. trigger an exception that is instantiated from JNI.

So while your workaround might work, it could be dangerous.

Ad files: As per GraalVM's decision, graphics related libs are not statically linked any more.

Quarkus deals with that by packing them next to the created executable for you.

The result is that where you copied 1 file, you have to copy libs as well now, e.g.
https://github.com/quarkusio/quarkus-quickstarts/blob/main/awt-graphics-rest-quickstart/src/main/docker/Dockerfile.native#L31

@Karm Karm closed this as completed Oct 3, 2023
@Karm
Copy link
Member

Karm commented Oct 3, 2023

Closing it as this is a proverbial "feature, not a bug". I will try to find a place where to note the fact about the libs better.

@antonwiens
Copy link
Author

Hi, i have a lot of integrationtests for everything, and in the statically linked native image everything works fine, without copying any libs to the application image. But thanks for your explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants