Unexpected Java Maven project naming

Viewed 39

I tried to make several Java Maven projects in Eclipse but every time I create a new project the groupId section is missing from the Java folder structure.

For example, I've created an Eclipse Maven project and here is the auto generated pom.xml :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.facebook</groupId>
  <artifactId>profiler</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</project>

However it is clear that the groupId is present (com.facebook) it is never shown in the folder structure and every import looks like:

import profiler.mypackagename.MyClass

instead of:

import com.facebook.profiler.mypackagename.MyClass

The com.facebook part isn't shown in the folder structure either. What do I wrong? I try to follow the Java conventions, went through lot of tutorials but I can't figure out what am I missing here.

1 Answers

Group id and package are unrelated concepts that just happen to look a lot alike.

Group id is only for organizing related maven projects. If you look at your local maven repository (under ~/.m2/repository) you’ll see it creates a hierarchy based on groups that it uses to store the different artifacts.

Package is a java language feature for organizing code so that classes get unique names. It doesn’t know about maven.

Java was created before maven, java code shouldn’t know about maven unless you’re implementing a maven plugin. Even then package doesn’t have anything to do with group ID.

You did nothing wrong, what you’re seeing is normal.

Related