Using Eclipse Maven project, import new version of a class from a jar file created from another Maven project

18 Views Asked by At

I have a Maven project, say Project A, with a java file that includes the following import statement.

import org.nhindirect.config.model.Address;

A version of the Address class is also in another java file in another Maven project, Project B. I modified the class in Project B, adding a helloWorld method to it. Then, I ran "mvn clean package" on Project B using the Maven Build... tool in Eclipse to create a jar file.

In Project A, I now want to import the Address class in the newly created jar file instead of importing the old Address class as indicated above. I have added the new jar file to the Build Path of Project B in Eclipse and I can execute the method that calls the helloWorld method within Eclipse. However, when I try to run "mvn clean package" using the Eclipse Build... tool in Project A, I get the following.

"error: cannot find symbol ... symbol: method helloWorld(String)"

I am guessing that the import statement is importing from the old version of the Address class instead of the new one from the jar file when trying to Build Project A in Eclipse. I have been told that Maven does not use the Build Path when performing a Build, which I guess is the issue here.

I have a couple of questions.

  1. How do I find the path to the class containing the code that the import statment is importing?

  2. How do I get Project A to use the new class instead of the old one?

I have copied the jar file to the ../src/main/resources/ directory of Project A, then added the following to the pom.xml file for Project A.

<dependency>
    <groupId>com.config.model</groupId>
    <artifactId>sconfig-model</artifactId>
    <version>6.0.1</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/config-model-6.0.1.jar</systemPath>
</dependency>

I then tried to change "import org.nhindirect.config.model.Address;" to "import com.config.model", but in the IDE it says "The import com.config cannot be resolved".

0

There are 0 best solutions below