What's the convention for java package names without a domain association?

前端 未结 5 1527
刺人心
刺人心 2020-12-07 20:40

I can\'t find a Q/A on SO that answers my exact question, so I figure I\'d post it and see what comes back.

As far as the naming convention goes for Java pa

相关标签:
5条回答
  • 2020-12-07 20:56

    One convention is to use the domain name of the hosting provider, e.g.

    com.github.myrepositoryname
    net.sf.sourceforge.myproject
    com.googlecode.myproject
    

    Benefits:

    • your package namespace will be unique, since the hosting provider won't have two projects of the same name
    • it's only as expensive as the host's costs, many of which are free
    • it can be an easy way to fulfil Sonatype's requirements if you want to get your project into Maven Central

    Drawbacks:

    • if you decide to change providers, you either have package structures which are out-of-date, or you introduce backward-incompatible changes to keep the source in line with your new provider
    0 讨论(0)
  • 2020-12-07 21:09

    Domain names can be had for free. For example dyn.com offers free domain names of the form 'whatever.dyndns.org' at http://free.domain.name/

    0 讨论(0)
  • 2020-12-07 21:12

    In a professional environment, the convention is to use reverse domain. In an environment that's more associated with yourself, you can use org.projectname.packagename.*.

    It's a convention, not a hard and fast rule. You're free to use whichever domain naming style you like.

    0 讨论(0)
  • 2020-12-07 21:13

    If you are the only coder, you can just use your name. My name is Jannis Froese, so I would use

    jannisfroese.projectname.stuff

    or if you want to stay with 'valid' domain names

    localhost.jannisfroese.projectname.stuff

    (localhost is a reserved top level domain)

    Of course this only works if your name is sufficiently unique, so that a collision is unlikely enough

    0 讨论(0)
  • 2020-12-07 21:17

    If you are going to be distributing a lot of stuff, I would really suggest getting a domain name. Another alternative however would be to use your e-mail: e.g. bob@gmail.com would become com.gmail.bob. This is less common than using domain names but is still done by some and still ensures uniqueness.

    0 讨论(0)
提交回复
热议问题