Automatic module naming

Given a JAR file, how does the platform know what to name it? For instance, if I were to drop the JAR file we are currently working with--commons-collections4-4.1.jar--into the module path, what would be the name of the module that gets created from it?

Naming of an automatic module is based off of the name of the JAR file, without the .jar extension. For example, if your JAR is named foo.jar, the name of the automatic module is foo! But, wait! What about invalid characters? It's very common to have the - character in the JAR name, but it's not allowed in module names. In such cases, the - character is automatically replaced by the . character. So, if the JAR file's name is my-lib.jar , the name of the automatic module would be my.lib.

While this naming works, it can be a hassle. It's because most JARs (especially ones from Maven or Gradle build systems) commonly have the version number in the name. This means that every time you get a new version of the JAR, the name of the module changes! To prevent that, and to make the library module names consistent, the automatic module name drops the version number from the name.

In summary, given a JAR file name, the automatic module naming does the following:

  • It drops the .jar file extension
  • It replaces - characters with .
  • It removes the version string

Thus, the JAR, commons-collections4-4.1.jar, gets the automatic module name-- commons.collections4.

Here are a few more examples:

JAR file name

Automatic module name

commons-lang-1.2.10.jar

commons.lang

spring-core-4.3.10.RELEASE.jar

spring.core

guice-4.1.0.jar

guice

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.201.217