Naming convention for java 9 modules [duplicate]
Asked Answered
C

1

5

What's the naming convention for java 9 modules? Let's say my package name is me.jasonyeo.awesome.project, and whenever I create a module-info.java file in IDEA, it would suggest me to name it awesome.project

Is that the convention? Or should I name it me.jasonyeo.awesome.project?

Carew answered 7/6, 2018 at 8:12 Comment(0)
A
9

It seems, IDEA’s suggestion is based on the fact the Java’s builtin modules have two components, e.g. java.base or java.desktop, but that doesn’t make a good suggestion for 3rd party modules.

JLS §6.1, Declarations says:

The name of a module should correspond to the name of its principal exported package. If a module does not have such a package, or if for legacy reasons it must have a name that does not correspond to one of its exported packages, then its name should still start with the reversed form of an Internet domain with which its author is associated.

Example 6.1-2. Unique Module Names

com.nighthacks.scrabble
org.openjdk.compiler
net.jcip.annotations

You may find the cited part faster using the direct link to the example

So your assumption is right, the recommended module name is me.jasonyeo.awesome.project, not awesome.project.

Ahmad answered 7/6, 2018 at 10:58 Comment(2)
Might be redundant and I am not sure if there is such a feature, but this moved under the original question instead would still add further meaning to it(both the question and the answer). Just an opinion :)Miru
@nullpointer well, the questions are linked now. I hesitate to create another identical answer and would rather wait for Stackoverflow to merge the questions. (Though, honestly, I don’t know when and under which circumstances this actually happens.)Ahmad

© 2022 - 2024 — McMap. All rights reserved.