java 如果我没有关联的域,我应该如何命名包?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/166051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 11:15:46  来源:igfitidea点击:

How should I name packages if I don't have a domain associated with me?

javanamespacespackages

提问by Bernard

So most Java resources when speaking of packages mention a com.yourcompany.projectsetup. However, I do not work for a company, and don't have a website. Are there any naming conventions that are common? An email address, perhaps?

因此,在谈到包时,大多数 Java 资源都提到了com.yourcompany.project设置。但是,我不在公司工作,也没有网站。是否有任何常见的命名约定?也许是电子邮件地址?

采纳答案by Stu Thompson

Use a top-level domain like 'bernard' or something else unique. The important part is that the domain is unique so that you avoid clashes, and not that it starts with a real Internet top-level domain like org or com. E.g.

使用顶级域名,如“bernard”或其他独特的域名。重要的部分是域是唯一的,这样您就可以避免冲突,而不是从真正的 Internet 顶级域(如 org 或 com)开始。例如

import java.util.*;
import bernard.myProject.*;
import org.apache.commons.lang.*;

回答by brianegge

If your creating an open source project, you could register it with Sourceforge and use net.sourceforge.myproject. This is common with a lot of Java projects. An example is PMD http://pmd.sourceforge.net/.

如果您创建一个开源项目,您可以将它注册到 Sourceforge 并使用 net.sourceforge.myproject。这在很多 Java 项目中都很常见。一个例子是 PMD http://pmd.sourceforge.net/

回答by Rafa? Dowgird

Good advice on this topic found on the web: "Start your package names with your email address, reversed.[...] Or, host your code at a site which will give you a slice of their domain."

网上找到的关于这个主题的好建议:“用你的电子邮件地址开始你的包名称,反向。[...] 或者,在一个站点上托管你的代码,这会给你他们的域的一部分。”

回答by belugabob

Why not register a domain?

为什么不注册域名?

They're fairly cheap and doing so will guarantee that you don't clash with anybody else (or at least give you the satisfaction that if a clash does occur, it's the other person who will have to rewrite their code).

它们相当便宜,并且这样做可以保证您不会与其他任何人发生冲突(或者至少让您满意,如果确实发生了冲突,那么另一个人将不得不重写他们的代码)。

Either register your own name, or try to make up a name that you may use as the basis for a business at a later date.

要么注册您自己的名字,要么尝试创建一个您可以在以后用作企业基础的名称。

  • bernard.surname.net
  • madeupname.net
  • bernard.surname.net
  • madeupname.net

This will cost you less than 10GBP per year.

这将使您每年花费不到 10 英镑。

Personally, I'd go for the made up name approach, as it's likely to look more professional (unless you choose something really strange).

就我个人而言,我会采用虚构的名称方法,因为它可能看起来更专业(除非你选择一些非常奇怪的东西)。

An added advantage is that a lot of domains will come with email capabilities, giving you a better email address than [email protected].

一个额外的优势是许多域都带有电子邮件功能,为您提供比 [email protected] 更好的电子邮件地址。

回答by Michael Borgwardt

Note that the "reverse domain name" thing is just a convention: useful since it definitely avoids clashes if everyone adhers to it, but you don't have to follow it.

请注意,“反向域名”只是一个约定:很有用,因为如果每个人都遵守它,它肯定可以避免冲突,但您不必遵循它。

Just choose a name that you can be reasonably sure nobody else will use and which is not registered as trademark by anyone- because that's the one way you could actually get into legal trouble.

只需选择一个您可以合理确定其他人不会使用且未被任何人注册为商标的名称- 因为这是您实际上可能陷入法律麻烦的一种方式。

And that means it's in fact a rather bad idea to use some sort of "subdomain" of a free service you're using, like deviantart or a dyndns or free mail service! Because most (if not all) of those domains are trademarked terms, and if your projects ever gets widely distributed, it could be seen as violating the trademark. Just because they allow you to use that name as an email address (or whatever) doesn't mean you can use it for anything else - in fact, their EULA almost certainly restricts usage to exactly that one purpose.

这意味着使用您正在使用的免费服务的某种“子域”实际上是一个相当糟糕的主意,例如 deviantart 或 dyndns 或免费邮件服务!因为这些域中的大多数(如果不是全部)都是商标术语,并且如果您的项目被广泛分发,则可能会被视为侵犯了商标。仅仅因为他们允许您使用该名称作为电子邮件地址(或其他任何名称)并不意味着您可以将其用于其他任何用途 - 事实上,他们的 EULA 几乎可以肯定地将使用限制在同一目的。

回答by Donal Tobin

What you can do also is register a domain (actually a sub-domain) through a service such as DynDns (or one of the equivalents) and then use that domain name. You will be the sole controller and it is freeand easy to maintain. They have a choice of 88 top domains at the moment (October 2008). dyndnsdynamic dns service

您还可以做的是通过诸如 DynDns(或等效项之一)之类的服务注册域(实际上是一个子域),然后使用该域名。您将是唯一的控制者,它是免费且易于维护的。他们目前可以选择 88 个顶级域名(2008 年 10 月)。 dyndns动态 dns 服务

回答by Alan

For my own personal work when I don't have a namespace, I go for something simple like org.<myname>.*

当我没有命名空间时,对于我自己的个人工作,我会选择一些简单的东西,例如 org.<myname>.*

回答by Axeman

I've been in a couple different companies who write house java classes. Often they're just com.blah.blah.blahwithout regard to whether there's a actual domain name behind it.

我曾在几家编写内部 Java 类的不同公司工作过。通常他们只是com.blah.blah.blah不考虑其背后是否有实际的域名。

回答by thSoft

IMHO, best if it does not depend on any external information, such as hosting provider or company (it could be released to the open source community), since package-level refactoring is not quite desirable, especially in the case of frameworks and libraries. I suggest choosing your project name carefully and unambiguously, then using org.<project name> as the root package.

恕我直言,最好不依赖于任何外部信息,例如托管提供商或公司(它可以发布到开源社区),因为包级重构不是很可取,尤其是在框架和库的情况下。我建议您仔细明确地选择您的项目名称,然后使用 org.<project name> 作为根包。

回答by Uri

Many people have their own websites and relatively unique names (or login names).

许多人都有自己的网站和相对独特的名称(或登录名)。

If your name is Bernard Something, you may own BernardSomething.com, making com.bernardsomething.xxxx (or com.bsomething.xxx) a legitimate package name IMHO for personal code.

如果您的名字是 Bernard Something,则您可能拥有 BernardSomething.com,从而使 com.bernardsomething.xxxx(或 com.bsomething.xxx)成为个人代码的合法包名称恕我直言。

That being said, If your project name is unique, you may want to name the package after that.

话虽如此,如果您的项目名称是唯一的,您可能希望在此之后命名包。

And of course, get the domain after your name if you don't own it yet!

当然,如果您还没有拥有域名,请在您的名字后获取域名!