Anthony Elliott
Anthony Elliott

Reputation: 3001

Recommended Maven package structure?

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?

Upvotes: 0

Views: 2515

Answers (2)

khmarbaise
khmarbaise

Reputation: 97389

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

Upvotes: 4

qqilihq
qqilihq

Reputation: 11454

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

Upvotes: 6

Related Questions