maven) into a jar file using jlink. It requires my project to be modular. In order to make it modular (I use default module, I don't need more modules), I need to create module-info.java
I feel desperate. I tried to create it many times but always get some errors, like "this module does not exist" and other stupid stuff.
I suck at modularity in java.
Any idea how to create module-info.java?
I don't have experience using jlink directly, but I used a maven plugin for that and it was pretty straightforward to setup: 1. Create module-info.java and compile all your classes to a jar with maven-jar-plugin. 2. Download library jars if there are any (they should be modularized already) with maven-dependency-plugin. 3. Specify what modules you want to be built in the plugin config and where all the jars are located. 4. You get a custom runtime with your program already embedded into it. module-info.java Suppose your sources located under app/src/main/java/com/example/application and your main class is com.example.application.Main. Your module-info.java should be put at app/src/main/java/module-info.java and look like this: module com.example.application { opens com.example.application; exports com.example.application; } If you want to introduce any library dependency, just add requires com.library; there. Honestly, I don't remember the difference between opens and exports, maybe exports is enough. I used opens & exports for a package with my main class, and only exports for all other packages. jlink plugin: https://github.com/moditect/moditect The description says Java 9, but it works fine with later versions. Example configuration: https://pastebin.com/9yFmKi1L
Обсуждают сегодня