If you are using Maven, you can use the add-module-info
goal of the moditect plugin. Below is a snippet of pom.xml I used to make the h2 jdbc driver and engine work with jlink. The plugin creates a patched copy of the plugin in ${project.build.directory}/modules which can then be jlinked in. I had to create the moduleInfoSource
section myself. To do that I used jdeps --multi-release=11
, java --describe-module
and the moditect:generate-module-info
goal and examining the manifest file to work out the requires statements etc. - for these to work you have to include all the dependencies of the JDBC jar you are trying to jlink. H2 has a lot of 'optional' features - I had to manually mark the requires for those as static. All this is pretty tedious, but if you do the same for the SQL Server JDBC driver, it should work for future releases, until an official modular component is released:
<plugin>
<artifactId>maven-jlink-plugin</artifactId>
<version>3.1.0</version>
<extensions>true</extensions>
<configuration>
<launcher>myapp=myappmodule/mypackage.MainClass</launcher>
<modulePaths>
<modulePath>${project.build.directory}/modules</modulePath>
</modulePaths>
</configuration>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.0.0.RC2</version>
<executions>
<execution>
<id>add-module-infos</id>
<phase>generate-resources</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
<modules>
<module>
<artifact>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.214</version>
</artifact>
<moduleInfoSource>
module com.h2database {
requires java.compiler;
requires jdk.net;
requires static lucene.core;
requires static lucene.queryparser;
requires static slf4j.api;
requires static jakarta.servlet;
requires transitive java.desktop;
requires transitive java.instrument;
requires java.logging;
requires transitive java.management;
requires static java.naming;
requires transitive java.scripting;
requires java.sql;
requires transitive java.transaction.xa;
requires transitive java.xml;
requires static javax.servlet.api;
requires static org.locationtech.jts;
requires static org.osgi.service.jdbc;
requires static osgi.core;
provides java.sql.Driver with org.h2.Driver;
}
</moduleInfoSource>
</module>
</modules>
</configuration>
</execution>
</executions>
</plugin>