Quick background information for context: I'm writing a relatively small tool for a small gaming community to download and manage user generated content. It's a modular Java 24 + JavaFX Project done with Maven and IntelliJ.
I store data on a SQLite DB. So far I've used bare-metal JDBC and wrote queries myself. As the tool grows, I would like to simplify DB access. At work we use Hibernate ORM in a Jakarta EE environment with Jakarta Contexts and Dependency Injection (CDI) etc., but I've read you can use Hibernate without relying on dependency injection.
So I've tried Hibernate for my tool and it does work well in my dev environment. Problems arise when trying to package a build via jlink, specifically using the javafx-maven-plugin to make things a lot easier for me.
The downside is that Hibernate does not seem to be modularized. Meaning I cannot easily package it with jlink. Running mvn javafx:jlink reports the "automatic module cannot be used with jlink".
I've then tried EclipseLink as an alternative Jakarta Persistence (JPA) implementation, had no issues with automatic modules but other resources apparently not being properly packaged with jlink. Specifically some locale resources appeared to be missing when trying to launch the packaged app, so they got left out the final package.
The last resort would be trying some SQL-first libraries like jOOQ to at least make it more bearable than plain JDBC. But I'd really prefer a Jakarta Persistence/ORM approach to keep database handling as easy and painless as possible.
Does anyone have a working approach I can use for my case? Or share your setup that actually works for you? Or find a way to get any Jakarta Persistence implementation to work well with the module system and Maven/JLink? The reason I'm using these is that packaging really is as simple as invoking a single Maven goal and for the most part that worked really well. Especially because of that I'm hesitant to get into any other packaging method, like the other jlink Maven plugin or something like jpackage, which seem to be very tedious to configure and get working.
The remaining issue that prevented my jlink build was rather simple to solve, thanks to a crucial hint in the comments by jewelsea. So here is a more complete overview of a working scenario.
EclipseLink is a modular dependency that works well with jlink packaging through the javafx-maven-plugin. To satisfy dependency modules on jakarta.transaction, an additional dependency to jakarta.enterprise.cdi-api is needed in your Maven project, even if CDI is not used in the project itself.
Required modules in the module-info.java file would be:
include-localesThe last missing step is to let jlink include locales, so the necessary resources needed for EclipseLink are bundled with the application. For this, an option needs to be added to the javafx-maven-plugin:
<options>
<option>--include-locales=en</option>
</options>
This way, there are no dependencies on automatic modules that jlink can't handle (like for example with hibernate) and the packaging and resulting runtime image works just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With