Eclipse: "package...does not exist" when building a Maven package that references a class in another project

23 Views Asked by At

In Eclipse IDE for Java Developers 2020-12, I have created two projects, "a-test-class-jar" and "a-call-test-class". In the first of these, I have created a class called "ATestClass" as follows.

package com.testclass.maven.a_test_class_jar;

public class ATestClass {
    
    public String getTestResults() {
        
        return "Hello from ATestClass";
        
    }

}
package com.testclass.maven.a_call_test_class;
import com.testclass.maven.a_test_class_jar.ATestClass;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {

        ATestClass hw = new ATestClass();

        System.out.println(hw.getTestResults());

    }

}

I have added the "a-test-class-jar" project to the Build Path of the "a-call-test-class" project by

  1. Right clicking the "a-call-test-class" project
  2. Selecting "Build Path" then "Configure Build Path"
  3. Selecting the "Projects" tab, then clicking the "Add" button
  4. Checking "a-test-class-jar" from the list of options, then cliking "OK"
  5. Clicking "Apply and Close"

After doing the above, when I run the the main method of the App class of the "a-call-test-class", it successfully instantiates the hw method and prints the "Hello from ATestClass" result from the getTestResult method of the "a-test-class-jar" class.

I am able to run "clean package" to build the jar file for the "a-test-class-jar" project. However, when I try to do the same for the "a-call-test-class" project, I get the following.

"...package com.testclass.maven.a_test_class_jar does not exist"

I have done Google searches for answers including variations on combinations of the terms "eclipse", "maven", "package", and "does not exist" as well as on questions such as "how to build a maven package in eclipse that references classes in other projects".

Some of the results indicated solutions using pom.xml files. Is this necessary? Is it not sufficient to add the other project to the Build Path as described previously?

Again, when I run the method in Eclipse, it runs successfully, but I get the "package...does not exist" error when I try to build the Maven package. Can somone please tell me what I need to do to build a Maven package that references a class in a package in another Maven project?

0

There are 0 best solutions below