1

In a school project, we are supposed to use maven enabled project. Maven is a great system for managing dependencies, so I'm quite happy I'll finally learn to use it.

However I already started project as Netbeans project and I'm now struggling how to reconfigure it. When creating the project IDE advised me to call it com.myname. This resulted in redundant empty folder com/myname/{sources start here}. Windows explorer isn't as smart as GitHub and doesn't skip empty folder which makes it very annoying.

I'm strongly considering that I'll call the project just myname. Is that valid? What are the risks of breaking this convention? Where did this convention come from and what does com abbreviation mean?

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • possible duplicate of [Do you really use your reverse domain for package naming in java?](http://stackoverflow.com/questions/189209/do-you-really-use-your-reverse-domain-for-package-naming-in-java) – Smutje Mar 03 '15 at 12:13

4 Answers4

3

com is part of a reverse domain. So if your domain is

somecompany.com your maven artefacts should be named com.somecompany.awesomeThingy

This makes sure we don't get name clashes when I publish my

com.someothercompany.awesomeThingy

This is also the naming convention for java packages.

All this doesn't really matter as long as your maven repos are private. Once you intend to publish artifacts to maven central though, there are rules enforcing that you name artifacts using a domain you control.

And of course there are other TLDs around, so org, de and many more are options too.

Community
  • 1
  • 1
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • That seems to imply that one must be a domain owner to publish libraries. – Tomáš Zato Mar 03 '15 at 12:15
  • I'm not sure how strict these rules are, and if there are exceptions, but basically yes. – Jens Schauder Mar 03 '15 at 12:17
  • 1
    If this is for a school project, you most likely do not want to publish your project to Maven Central. – Jesper Mar 03 '15 at 13:19
  • @TomášZato Not necessarily. If your project is hosted on GitHub then make your package `com.github.awesomethingy` as long as it is unique there should be no problems. – Sled Jun 01 '16 at 13:48
  • 1
    @ArtB I think the better option would be: io.github. because via github pages you actually control that domain. – Jens Schauder Jun 01 '16 at 17:05
  • @JensSchauder you might move of the project and someone else might pickup the mantle. The domain should reflect the project not you. Also the precedent for this has be established under [`net.sf`](https://repo1.maven.org/maven2/net/sf/) and [`net.sourceforge`](https://repo1.maven.org/maven2/net/sourceforge/) ([SourceForge](https://sourceforge.net/) was essentially a predecessor to GitHub). – Sled Jun 01 '16 at 17:54
1

Of course it is valid. Eclipse recommends this, because it usally makes sense for an organization. For a school project, not so much.

Anyway, this is a common convention in the Java world, you should get used to it :)

meskobalazs
  • 15,741
  • 2
  • 40
  • 63
  • The thing is that I'm in Czech Republic and I own no domain. At that point, using `com` makes really no sense. – Tomáš Zato Mar 03 '15 at 12:16
  • You can use `cz` of course :) I myself always use `hu.meskobalazs` for my projects. And no, I don't have this domain. – meskobalazs Mar 03 '15 at 12:17
  • Further more, if I have site on webhosting subdomain, would I use something like `com.freesites.myproject...`? – Tomáš Zato Mar 03 '15 at 12:19
  • You could. You don't have to map to a real URL, two whole point is to come up with a globally unique identification, so you can avoid any potential name collisions with external dependencies. Otherwise, it is totally your call. – meskobalazs Mar 03 '15 at 12:22
1

It's just part of a Java package name.

Package names in Java look like domain names, but in reverse order. For example if someone is working for "somecompany.com" then he or she will usually use the package name com.somecompany.someproduct.

This is just the convention in the Java world. It's not required to adhere to this convention.

Jesper
  • 202,709
  • 46
  • 318
  • 350
1

Well, it just a Java Convention. Ideally com refers to Commercial, which is used for commercial purpose.

You can use anything instead of com, like org. or edu.

   <groupId>org.codehaus.mojo</groupId>
    <artifactId>parent</artifactId>
    <version>1.0</version>

But going forward in your future, you will certainly need to follow the same code structure. So, how about practicing from college project itself.

dildeepak
  • 1,349
  • 2
  • 16
  • 34