Git Product home page Git Product logo

Comments (3)

sgammon avatar sgammon commented on May 31, 2024 1

Hey @erkieh,

I am not a Micronaut project contributor, but I can probably still help you out with this. GraalVM performs class initialization at either build time or run time. Which classes are loaded and in what order depends on each application, of course, so these errors vary quite a bit and may surface in Launch-generated samples.

It is frequent to run into these errors when building a native app with GraalVM, and it isn't always immediately clear what to do, but there are some ways to figure it out. Here are the steps I take, which nearly always work eventually:

  1. Mark the class as --initialize-at-build-time
    If you pass --initialize-at-build-time=<class> during the build, to native-image, you are telling the Native Image builder that the subject class is OK to initialize at build time, and this alone will often clear up the error, so long as the class is sensible to initialize at build time in the first place, which isn't always true. In that case, you can...

  2. Mark the class as --initialize-at-run-time
    If you pass --initialize-at-run-time<class>, native-image will try to defer initialization for that class and any related necessary classes. For example, say you have a class which uses epoll on Linux; epoll may not always be available, and you may want to fall back to NIO. You could initialize such a class at runtime to avoid the build-time environment from governing whether support is detected.

  3. Run with --trace-object-instantiation
    When you're not sure which of the above to use for a given class, you can use --trace-object-instantiation=<class>, which will print more information about why the class in question was instantiated at build time.

What I see from your log is that several Logback classes are showing up as initialized at build time, which makes sense: logback.xml is loaded early in the program lifecycle. There are some Netty classes too. If you have trouble figuring out the right flags to use, I can try to dig up one of the cases where we also encountered these and see what flags made it work.

from micronaut-core.

erkieh avatar erkieh commented on May 31, 2024

Hi @sgammon
Thanks for replying. I did try creating a reflect-config.json in a real project with the help of trace flags, but it felt like a rabbit hole with no bottom. It would be interesting to see what got it working in your case.

from micronaut-core.

graemerocher avatar graemerocher commented on May 31, 2024

This has to be fixed upstream in native image.

from micronaut-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.