Вопрос

Is there a standard/recommended format to follow when creating packages in a maven project? I understand that the directory structure is supposed to follow a proscribed format and wasn't sure what the best way is to insert my packages.

Should my package structure be main.java.com.foo.bar and test.java.com.foo.bar or remove the beginning and then have com.foo.bar and com.foo.bar.test?

Это было полезно?

Решение

main and test do not belong to the package name. You would put classes and tests in the same package (i.e. no additional test in the package name; com.mycompany.app in the example below), but distributed to main and test directory respectively.

Example for a project structure (taken from here):

my-app 
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- com
    |           `-- mycompany
    |               `-- app
    |                   `-- App.java
    `-- test
        `-- java
            `-- com
                `-- mycompany
                    `-- app
                        `-- AppTest.java

Другие советы

Your package structure should be like this:

com.foo.bar

which means in directory layout:

src
 +-- main
 !    +-- java
 !          +-- com
 !               +-- foo
 !                    +-- bar
 !                         +-- MyFirstClass.java
 +-- test
      +-- java
            +-- com
                 +-- foo
                      +-- bar
                           +-- MyFirstClassTest.java
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top