-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Cannot build native image for trivial app with SLF4J and Log4J2 #2008
Comments
Hi, @mipastgt
Works fine! Trying to compile with
Next trial
Is it really the canonical way to compile with native-image? Thx |
@jgranduel On UNIX the command line would be: |
@mipastgt |
I learned by now that the issue is probably caused by using MethodHandles which, according to https://github.com/oracle/graal/blob/master/substratevm/LIMITATIONS.md , are not supported in native images. So what is the policy to deal with code which uses MethodHandles. Log4J2 is just one of these but maybe the most popular one. The error message All methods from java.lang.invoke should have been replaced during image building. suggests that these methods are somehow replaced automatically during the image build but that is probably just wishfull thinking. So what am I supposed to do? Rewrite Log4J2 or what? Just for the record: The problem was introduced in Log4J 2.8 |
@mipastgt Currently the support the support for |
Any suggestion which version of |
@neomatrix369 I have mentioned that here: Link |
GraalVM 21.0.0 now supports MethodHandles, isn't that fix the issue? |
Maybe. I am not using Log4J2 anymore and so haven't tried it. |
I spend a lot of time to get it working with GraalVM 21.0.0 and log4j 2.10.0 (and optimize the reflect-config.json, to reduce the size of the native image from 28MB to 18MB): |
Nice, I'll take a look on your config, thanks! |
@muellerc Just a side note. If you really want to reduce the size of the native image, then have a look at |
Oh, so does it work for graalvm compiled binaries @mipastgt ? |
Yes it does. Here is a little write-up of my experience (second half of the article): https://www.mpmediasoft.de/articles/JFX-Bundles/JFX-Bundles.html |
Small correction, here are my numbers: native-image:
native-image compressed with UPX (using the --best option):
|
Do you know why the CPI increased that much? probably related with unzipping during UPX executable startup? |
Updated app for AWS Lambda Powertools logging. build.gradle Added Powertools dependencies, which required lowering JVM target from 17 to 16 due to AspectJ limitation. reflect-config.json, resource-config.json Adding log4j2 makes GraalVM complain loudly. You have to add a lot to those files to get it to run without crashing. Followed example here: https://github.com/muellerc/graalvm-sandbox/tree/main/log4j2-sandbox/src/main/resources/META-INF/native-image/com.amazonaws.sample.cmr.sns-throughput-optimization/log4j2-sandbox From this thread: oracle/graal#2008
For this trivial application
the attempt to create a native image fails with an error message which is far too long to be shown here and I can't make any sense out of it. The idea was to first compile the application and then run it with the native-image-agent and after that build the native image based on the collected data.
This works if the build is configured to use the SLF4J simple binding but when I configure it to use LOG4J2 instead, the native build fails completely. The first two steps (copiling, running with agent) work in all cases.
Because native-image thinks there is something missing, I was asked to add the following options to it:
This should have worked because the app works nicely on the VM but it fails with native-image.
I have added a ZIP-file with the whole project to demonstrate the issue. It contains a build script and a Maven POM which exercise the above mentioned steps.
My tests where done on macOS 10.14.6 and GraalVM 19.3.0 (11) CE.
Hello.zip
The text was updated successfully, but these errors were encountered: