Comments (3)
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:
-
Mark the class as
--initialize-at-build-time
If you pass--initialize-at-build-time=<class>
during the build, tonative-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... -
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 usesepoll
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. -
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.
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.
This has to be fixed upstream in native image.
from micronaut-core.
Related Issues (20)
- micronaut-bom jar package not kept up-to-date? HOT 2
- Async REST resource responding to a DELETE with HttpResponse.accepted() results in 404
- Support Graceful shutdown HOT 1
- Server request not available when controller binding parameter from json HOT 1
- File upload is limited to 1GB when using MultipartBody HOT 3
- BeanIntrospection dispath method generated is wrong for Kotlin extension functions.
- Micronaut inject-kotlin clashes with generated classes from Kotshi HOT 2
- add .zip / .png / .jpg to io.micronaut.http.MediaType HOT 2
- Latest version in Maven Repos is 4.3.7 HOT 5
- Memory leak on Micronaut HTTP server HOT 19
- MicronautHttpData cannot delete temporary files on Windows HOT 7
- Inability to inject `Collection<Provider<MyInterface>>` HOT 1
- Endpoint with int pathvariable returns 403 even if security is not enabled HOT 1
- Bean mappers - Updating existing bean instances
- Mybatis integration with mybatis HOT 1
- Annotations on beans not propagated to their intercepted classes
- docs: remove GORM
- Need add more information for introspected FieldElement HOT 4
- Unexpected behaviours with cron expression HOT 2
- Declarative HTTP client methods with primitive return types fail after upgrading to Micronaut 4 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from micronaut-core.