Use of reverse DNS notation in your Intellij project structure

已回答

There's some things I don't fully understand.

ConsiderThe main application, “HelloApplication”,which is in the path:

“src/main/java/dev/research/devcode/HelloApplication.java”

 

And the FXML view, “hello-view.fxml” which is in the path:

“src/main/resources/dev/research/devcode/view/hello-view.fxml”

And the for the FXML Loader in the main() method:

FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("/dev/research/devcode/view/hello-view.fxml"));

 

What I do not fully understand:

  1. why the need for the cascase of empty folders “/dev/research/devcode/” in  “src/main/java/dev/research/devcode/HelloApplication.java” when surely it would be better and easier to just have “src/main/java/HelloApplication.java”?
    1. Why did  Intellij add ““/dev/research/devcode/” to my resources package when I did not add it myself? [I added the /view package under this folder cascade to contain all the FXML files.
    2. [FXMLLoader() path ] For the FXMLLoader() path,  why is the path “/dev/research/devcode/”” and not “/resources/dev/research/devcode” ?
    3. This may seem a fundamental question, but I don't really fully understand I need for it, why the use of the reverse DNS naming style?

Thank you in advance.

 

0

Hi,

With Maven projects, IntelliJ IDEA derives their configuration and structure from pom.xml files.

In your case, a <sourceDirectory> is probably defined somewhere in the pom file with /dev/research/devcode/ in its path. Or some other option that changes the default path.

why is the path “/dev/research/devcode/”” and not “/resources/dev/research/devcode” ?

In IntelliJ IDEA, if you use class.getResource() to obtain a file and if this file resides in a directory marked as a Resource Root, you don't need to pass the entire path in the argument, only the part after the resource root dir.

why the use of the reverse DNS naming style?

There is no technical reason, only a convention to avoid conflicts. Reverse-DNS names are a simple way of eliminating namespace collisions, since any registered domain name is globally unique to its owner. 

Additional reading on the subject:

Merry Christmas!

0

请先登录再写评论。