Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven groupId and package name in java source

If I have a maven groupid com.mycompany.app, does it mean I need to name my package under the name of com.mycompany.app.*?

like image 704
user496949 Avatar asked Mar 06 '11 22:03

user496949


2 Answers

No, maven doesn't care what package names you use. Having said that, it's not a bad idea to make them consistent to make it a little easier to see which dependency a class comes from.

like image 122
tgdavies Avatar answered Oct 18 '22 14:10

tgdavies


While creating a maven project if you have mentioned values for both groupId and package name, then maven will consider the package name to place your java class.

For example:

mvn archetype:generate -DgroupId=gen.src -DartifactId=Iftekhar -DpackageName=com.src.Model -Dversion=2.0-Snapshot

In the above scenario App.java class will be created inside the package com.src.Model and the groupId value will not be considered.

But if you have mentioned only groupId value (and not package name) like below:

mvn archetype:generate -DgroupId=com.src.Controller -DartifactId=Iftekhar -Dversion=2.0-Snapshot  

Then App.java class will be created inside the package com.src.Controller.

like image 27
user3747182 Avatar answered Oct 18 '22 13:10

user3747182