10

I'd like to release an open source java library. I thought of using my last name as package name but I find that a bit weird. I'd like to use something more neutral like 'open.libname'.

Are there any recommendations on open source java package naming?

Igor Gatis
  • 4,648
  • 10
  • 43
  • 66
  • Close voters: there actually is an authoritative answer for "How should I name my Java packages?", using the reverse domain names described in the answers (see the notes at the end of [Java Language Specification section 6.1](https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.1)). I voted to close with a duplicate providing a good answer, but whose question doesn't exactly match this one -- if you know of a better duplicate, please use it instead. – Jeffrey Bosboom Jun 27 '15 at 01:48
  • possible duplicate of [Java packages com and org](http://stackoverflow.com/questions/2125293/java-packages-com-and-org) – Jeffrey Bosboom Jun 27 '15 at 01:49

4 Answers4

10

As the others said, start the package name with the reversed domain name:

Register a domain such as myproject.org and then use org.myproject.mymodule.

Or, if you don't have your own domain use the sub-domain where you host the code, e.g. if you host the code on myproject.sourceforge.net, use net.sourceforge.myproject.mymodule.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Puce
  • 37,247
  • 13
  • 80
  • 152
  • 1
    `net.sf` is a nice short prefix, if [sourceforge.net](http://sourceforge.net) is chosen for hosting. [sf.net](http://sf.net/) is a domain registered by sourceforge.net. – Joachim Sauer Mar 11 '11 at 09:01
  • I liked your suggestion. In my case it would be a awkard 'com.google.code.mylibrary' since this is not a google official code release. Alternatives? – Igor Gatis Mar 11 '11 at 12:33
  • 1
    @Gatis Did you see my suggestion of `com.googlecode.` in my answer? `googlecode.com` points to `code.google.com`. – Isaac Truett Mar 11 '11 at 14:10
4

The usual recommendation is to prefix your package with the name of a domain you own in reverse order: com.mydomain.mypackage. Since you own the domain, the chances of name collisions are reduced.

Also, a better choice for the package name is something that reflects the functionality of the package, rather than your own name. What will you use when you want to release your second (and perhaps totally unrelated) library?

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • You mean something like gatis.foo and gatis.bar for libraries foo and bar? – Igor Gatis Mar 11 '11 at 12:30
  • Yes. If you own a domain like gatis.com, you could use package names `com.gatis.foo` and `com.gatis.bar`. Don't go overboard, but the more you can make your package names unique, the less chance of problems from name collisions. (In many cases, the choice of package name isn't really important, but that's different when distributing a library. Also, places like Android Market use the package name of the launch class to identify apps.) – Ted Hopp Mar 11 '11 at 16:52
3

Where are you hosting your project? When I host a project on Google Code, for example, I tend to use com.googlecode.project-name (it seems rude to use com.google.code.project-name). I don't actually know what Google thinks about this, but it follows the example of many Sourceforge.net projects. If you have a personal/corporate domain then go ahead and use that one, of course.

Isaac Truett
  • 8,734
  • 1
  • 29
  • 48
2

This may or may not be the answer you're looking for.

The common convention is to reverse your personal/company domain name and prepend it to whatever the name of the package is.

So, if your domain is "www.feel.com" and your package name is "mypackage", then your fully qualified package name would be: com.feel.mypackage

Brian Driscoll
  • 19,373
  • 3
  • 46
  • 65