javamavenintellij-idea

Maven, package does not exist


I have a module whose pom file is:

<groupId>com.mycompany.Common</groupId>
<artifactId>common</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>common module</name>

In that artifact ('common'), I have a package named com.mycompany.common.objects. In the consuming package, my pom file is:

 <dependency>
            <groupId>com.mycompany.Common</groupId>
            <artifactId>common</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>pom</type>
 </dependency>

When I run mvn install it always complain: package com.mycompany.common.objects does not exist.

I tried explicit importing in the class where the error was:

import com.mycompany.common.objects

No luck. I tried in both the IDE (IntelliJ) and on the command line. Any ideas? Thanks


Solution

  • From your sample, we cannot see any artifact containing the package com.mycompany.common.objects you are using.

    You are adding dependency com.mycompany.Common:common as a POM (and you are declaring the packaging of com.mycompany.Common:common as POM too). If it is actually a JAR artifact that contains the package you need to use, then remove the packaging from the POM and dependency (which means, using default which is JAR).