I'm trying to add a JDBC connector module to my project with Java 11. I downloaded the MSSqlServer JDBC driver 7.2 for Java 11
https://www.microsoft.com/en-us/download/details.aspx?id=57782
I added the module :
requires com.microsoft.sqlserver.jdbc;
Yet when I try to clean+build, NetBeans tells me:
Error: automatic module cannot be used with jlink: com.microsoft.sqlserver.jdbc from file: /sqljdbc_7.2/enu/mssql-jdbc-7.2.2.jre11.jar
I'm pretty sure this is because the jar doesn't have a compiled module-info.java
. However, I was wondering if there is a way to inject one in there?
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>
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