문제

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