0

I have two Java eclipse projects in my workspace. Project ProjectA has class ClassA inside package packageA, and likewise, project ProjectB has class ClassB inside package packageB.

I have this simple code:

// ClassA.java
package packageA;

import packageB.ClassB;

public class ClassA {

    public static void main(String[] args) {
        ClassB b = new ClassB();
        String str = b.getStr();
        System.out.println(str);
    }

}


// ClassB.java
package packageB;

public class ClassB {
    private String str;

    public ClassB() {
        str = "Hello, World!";
    }

    public String getStr() {
        return str;
    }
}

The Problem: I am trying to debug main in ClassA. When I step into the ClassB constructor, I get the error "Source not found" with the button "Edit Source Lookup Path...". I tried to fix this by adding ProjectB to the "Source" tab of ProjectA's debug configurations, but still getting the same error.

The question: How do I fix this issue?

Alon
  • 616
  • 1
  • 7
  • 18
  • In what way is the dependency between projects being set up? – nitind Feb 24 '19 at 03:16
  • ProjectA depends on ProjectB, but not the other way around. ProjectA -> Properties -> Java Build Path: The "Projects" tab has ProjectB and the "Order and Export" tab also has ProjectB (unchecked). – Alon Feb 24 '19 at 13:51
  • Looks like you still have an `ClassB.class` somewhere in the build path of Project A. This class is used instead of the one from Project B, therefore the source is not found. Look at the build path and examine the Project A directories on file-system level (outside of Eclipse) for this file. – Robert Feb 24 '19 at 14:31

2 Answers2

1

I solved this issue as follows: When I encounter the "Source not found" page, I step out with the debugger a few times, until I get back to where I was in my code. Then, I step into again, and this time it works.

For reference, please see this answer.

Alon
  • 616
  • 1
  • 7
  • 18
0

They need to be on the same package tho , or try using maven project and include the package you want thru pom.xml

Leroy
  • 168
  • 10
  • I need `ClassA` and `ClassB` to be in different packages, which are in turn in different projects. Are there any other options other than transforming these projects into maven projects? – Alon Feb 24 '19 at 02:27
  • Did you try public ClassA extends ClassB ? – Leroy Feb 24 '19 at 02:37
  • No. I am asking how I can set-up the projects correctly, not how I can change the code. – Alon Feb 24 '19 at 13:56