Java Magazine, July/August 2018
ORACLE COM JAVAMAGAZINE JULY AUGUST 2018 59 libraries The problem is that Maven also does this The final step into the future that Java 9 brought is to turn your projects JAR file into a modular JAR file on Java 8 which then fails due to unknown command line options such as add modules As a solution Ive named the configuration files jvm9 config so they are ignored by default and then I let the CI server call a script that renames them all to jvm config before launching the build Its not exactly beautiful but it works I never dealt with these Maven features before building on Java 9 and in the beginning I wasnt enthused to dig through them But I found it to be a great opportunity to get to know Maven a little better and that has paid of many times over Your Library as an Automatic Module Congratulations If youve gotten this far your project is built and tested on Java 9 Your users will be thankful and will start using your library at first on the class path but soon theyll want to take the next step and use it as a module How does that work After all you have not created a module yet Automatic module crash course If users start modularizing their own project they have to declare each dependency including declaring your library with a requires directive For that to work though they need a module name to use with requires And they need to place that on the module path If the Java runtime encounters a JAR file without a module descriptor module info class on the module path it will create a so called automatic module for it Its just like a regular module but there are certain assumptions about its properties an automatic module exports all packages and can read all other modules The more interesting aspect is the name Ideally the automatic module name is defined with the manifest entry Automatic Module Name If thats not the case the module system derives a name from the JAR files name That fallback is obviously unstable across development environments and causes additional problems if your library ever changes its module name for example because you modularize it and give it a proper name
You must have JavaScript enabled to view digital editions.