18

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?

trilogy
  • 1,429
  • 13
  • 28
  • 1
    You can use `jdeps` to generate a `module-info.java` file then [compile it](https://stackoverflow.com/questions/47222226/how-to-inject-module-declaration-into-jar). Then you just need to add `module-info.class` to the JAR file, I believe. – Slaw Jun 19 '19 at 04:29
  • 4
    @Slaw this is a real pain. There are so many dependencies that will need to be modularized as well... Is there a way to use jlink to create a custom runtime but include extra legacy jars with the runtime outside ? – trilogy Jun 19 '19 at 14:39
  • Not with `jlink`. If you're using Maven you might be able to use [this plugin](https://github.com/moditect/moditect). Looks like they also have [a plugin](https://github.com/moditect/moditect-gradle-plugin/) for Gradle. You could also try [`jpackage`](https://jdk.java.net/jpackage/), though it's currently early-access and based on JDK 13. From my one-time experience with that tool it allows you to mix the modulepath/classpath _or_ explicit/automatic modules. However, unlike `jlink`, the `jpackage` tool provides zero support for cross-platform packaging. – Slaw Jun 19 '19 at 15:04
  • Note when I say, "_mix the modulepath/classpath or explicit/automatic modules_", I really do mean either-or. If your code is modular, and you want to use it on the modulepath, then everything needs to be on the modulepath. This is because explicit modules don't have access to the classpath (i.e. the "unnamed module"). The dependencies on the modulepath don't have to be explicit modules, however; they can be automatic modules. If your code is non-modular, then you can have stuff on the modulepath and your code on the classpath (you'll probably have to use `--add-modules` though). – Slaw Jun 19 '19 at 15:09
  • 2
    I think it is impossible to find any serious project that won't have modules with automatic module names, for example spring has them. So, jlink we can use only to create custom jre but not to link our project modules. – Pavel_K Nov 25 '20 at 19:07

0 Answers0