Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top