简体   繁体   English

maven 中的 package 和 groupId 有什么区别

[英]Whats the difference between package and groupId in maven

I understand the terms, groupId , artifactId and version .我了解术语groupIdartifactIdversion While reading about package , I can see it is The name of your root package.在阅读package ,我可以看到它是您的根包的名称。 The default is the groupId you entered before.默认是您之前输入的groupId . .

In that case, what is the difference between package and groupId ?在这种情况下, packagegroupId之间有什么区别? 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.好像您在问使用 Maven Archetype 生成新的 Maven 项目时package是什么意思。

The package is to configure the root java package that contains all the generated source codes.package是配置包含所有生成源代码的根java包。 So if you set the package to com.foo.bar , the generated project will contain a folder com/foo/bar/ in /src/main/java .因此,如果您将package设置为com.foo.bar ,则生成的项目将在/src/main/java包含一个文件夹com/foo/bar/

groupId , together with artifactId and version is a kind of an unique identifier of your library . groupId以及artifactIdversion是您的库的一种唯一标识符。 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 .这意味着在您将项目打包为 JAR 并将其发布到全世界之后,其他开发人员可以通过在他们的pom.xml指定正确的groupIdartifactIdversion将其导入到他们的项目中使用。

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.因此,该package只是您的项目内部使用的内部根包,它不会影响开发人员如何定位您的 JAR 并将其导入到他们的项目中。 The package and the groupId can be different. packagegroupId可以不同。

(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.) (当然,您应该将包命名为某个唯一的名称,这样它就不会与其他知名库发生冲突(例如,不要将其命名为java.langorg.springframework等)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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