默认Maven包中的域名

huangapple go评论60阅读模式
英文:

domain name in default maven package

问题

当我使用quickstart原型创建Maven项目时,它会在src/main/java目录中填充一个默认包,即"com.domain.my.project_name"。

是否有任何地方期望我使用这个包?如果我不将我的包命名为"com.domain.my.project_name.package_name",是否会引发问题?

英文:

When I create a Maven project using the quickstart archetype, it populates my src/main/java directory with a default package, "com.domain.my.project_name"

Is there anything that expects me to use this? Will I cause problems by not naming my packages "com.domain.my.project_name.package_name"?

答案1

得分: 1

简单地说:不需要。将包命名为域名是一种约定。没有任何强制规定让你遵循这个约定。谈到Maven原型:在大多数原型中,它只是一个示例,可以帮助你入门。如果你不确定是否要删除它,请使用任何良好的IDE(IntelliJ、NetBeans、Eclipse)提供的“安全删除”操作。

英文:

Simply put: no. Naming packages like domains is a convention. Nothing forces you to comply to that. Speaking of the Maven archetype: In most archetypes it’s just an example to get you started. If you are unsure about deleting it, use the safely delete action that any good IDE (IntelliJ, NetBeans, eclipse) provides.

答案2

得分: 1

当您的项目在个人使用之外发展到足够有用的程度时,您可能希望将其发布到Maven中央仓库,其中要求groupId是唯一的。域名在确保唯一性方面非常有用。对于Java包名称也是如此 - 一旦它们出现在其他人项目的类路径中,为它们取一个唯一的名称就显得很有礼貌 - 就像将它们放入具有匹配的groupId的构件中一样。

如果这似乎与您的代码不符,您将不会遇到任何问题。但是,如果您的项目不断发展并变成开源项目,您可能会遇到品牌问题。只需要看看org.apache.commons与commons-io之间造成的所有混淆就知道了。

英文:

When your project grows enough to be usefull outside of your personal use you may want to publish it to Maven Central, where groupId is required to be unique. Domain name is good in asserting uniqueness. The same applies to Java package names - as soon as they land in classpaths of other people's projects, uniquely naming them is just polite - as is putting them into artifacts with matching groupIds.

If this doesn't seem to apply to your code - you will encounter no problems. But if your project grows and gets opensourced you will face branding issues. Just look at all the confusion caused by org.apache.commons vs commons-io.

huangapple
  • 本文由 发表于 2020年10月9日 01:13:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/64267509.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定