0

I have two maven projects,

  1. testmvn
  2. mvnusedemo

testmvn:

    <groupId>com.avs</groupId>
    <artifactId>testmvn</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>testmvn</name>

mvnusedemo:

    <groupId>com.avs</groupId>
    <artifactId>mvnusedemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mvnusedemo</name>

now I have a class in project testmvn

package com.avs.Calculation;

public class AddNumbersME {
    public int addNumbers(int a, int b) {
        return a + b;
    }

    public int addNumbers(int a, int b, int c) {
        return a + b + c;
    }

}

i have run mvn install cmd, I got Build Success. In the local repo(.m2) I can see those jars

Now I am trying to use this class(AddNumbersME) in project mvnusedemo

  1. Added dependency in pom.xml of mvnusedemo
<dependency>
    <groupId>com.avs</groupId>
    <artifactId>testmvn</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

Now I can see the dependency added to the maven dependency folder in eclipse.

  1. Now trying to use the **AddNumbersME **
    public static void main(String[] args) {
        SpringApplication.run(MvnusedemoApplication.class, args);
        AddNumbersME a = new AddNumbersME(); // getting error - could not resolve 
    }

error: AddNumbersME cannot be resolved to a typeJava

need help, do I am missing something ??

2 Answers2

0

one of my friends helped me out, need to provide executions inside build -> plugin in pom.xml it looks like

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <classifier>exec</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

now it is working fine.

-1

You have the same group id in two of the projects. So use only import Calculation.AddNumbersME Don't add com.avs! Another suggestion: don't use uppercase package names such as Calculation. Use lower case calculation as the package name!

Onur Baştürk
  • 715
  • 5
  • 15
  • still the same, getting error. **The import Calculation cannot be resolved**, Even IDE is not recognizing and doing auto imports. – Vijayashankar Aruchamy Aug 25 '20 at 11:09
  • Make sure mvnusedemo project is reloaded. Which IDE do you use? Make mvn clean install for the mvnusedemo project too! – Onur Baştürk Aug 25 '20 at 11:12
  • @VijayashankarAruchamy I created two mvn projects (but not a Spring boot app, just a simple empty maven project) with the same group id and I used exactly the same naming of packages, classes, methods etc. with copy/paste from your question. It works! But as I say the import and maven reload is necessary! – Onur Baştürk Aug 25 '20 at 11:28