简体   繁体   中英

Whats the difference between package and groupId in maven

I understand the terms, groupId , artifactId and version . While reading about package , I can see it is The name of your root package. The default is the groupId you entered before. .

In that case, what is the difference between package and groupId ? I guess its always the same, or if they can be different than how? Someone explain

在此处输入图片说明

Seems like you are asking what does package means when using Maven Archetype to generate a new Maven project.

The package is to configure the root java package that contains all the generated source codes. So if you set the package to com.foo.bar , the generated project will contain a folder com/foo/bar/ in /src/main/java .

groupId , together with artifactId and version is a kind of an unique identifier of your library . That means after you package your project as a JAR and publish it to the world , other developers can import it to their project to use by specifying the correct groupId , artifactId and version in their pom.xml .

So , the package is just the internal root package used by your project internally and it will not affect how developer locates and import your JAR to their project. The package and the groupId can be different.

(But of course, you are supposed to name the package to some unique name such that it does not conflict with other well-known libraries (eg don't name it as java.lang or org.springframework etc.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM