I want to use Java 9 in my app. One of my dependencies has a jar name:
sdk-http-ahc-2_0
Unfortunately, when I try to change it to automatic module, the name for the module is not valid.
requires sdk.http.ahc.2_0; // not valid
Am I missing something with naming the module? What are my other options here?
The problem is that the module system does not identify 2_0
as a version number and hence doesn't strip it when determining the automatic module name. Unfortunately, 2_0
is not a valid Java identifier and can hence not be used as a segment in a module name.
The solution is to either rename the JAR or add the Automatic-Module-Name
entry to the JAR's manifest:
Create a file manifest.txt
with the following content:
Automatic-Module-Name: sdk.http.ahc
Then use jar
to append that line to the existing manifest:
jar --update --file sdk-http-ahc-2_0.jar --manifest=manifest.txt
Note that locally modifying existing JARs (name or manifest) can cause problems down the road. Consider changing the Maven version of the file to something like 2.0-patched-auto-name
(or similar) and add it to your local Maven repository. If the project is shared with other developers and you have a local Nexus, you can put it in there. Otherwise send a mail to everyone with the steps to add it to their local repo. 😜