To tell Eclipse about the dependency, you can set the Java Build Path
in SampleProject2
to require the SampleProject1
.
Step-by-step:
- Right-click on the Java project (
SampleProject2
in this case)
- choose
Properties
- Within the properties, choose
Java Build Path
on the left hand side
- Select the
Projects
tab.
- Press
Add...
- Select the dependent project (
SampleProject1
in this case)
- Press
OK
until you have closed everything.
- It should now work for you.
Here is a screenshot of your destination for the above:

Example of it working
Take two projects named as you have them. Here is what I have on disk (excluding non java and .project files):
$ find * -name *.java -o -name .project
RemoteSystemsTempFiles/.project
SampleProject1/.project
SampleProject1/src/com/example/sampleproject1/UsefulClassNeededElsewhere.java
SampleProject2/.project
SampleProject2/src/com/example/sampleproject2/ClassThatNeedsSomethingUseful.java
ClassThatNeedsSomethingUseful:
package com.example.sampleproject2;
import com.example.sampleproject1.UsefulClassNeededElsewhere;
public class ClassThatNeedsSomethingUseful {
private UsefulClassNeededElsewhere useful = new UsefulClassNeededElsewhere();
public UsefulClassNeededElsewhere getUseful() {
return useful;
}
}
UsefulClassNeededElsewhere:
package com.example.sampleproject1;
public class UsefulClassNeededElsewhere {
}
And finally the dependency set up as described above. That should make everything work, and your workspace should look like this:

As you can see, no error markers.
Things to keep in mind
You still need your build system to know about this dependency. i.e. your Ant file or other will need to know. Some build systems have excellent tooling in Eclipse, so that the dependencies will be calculated from the build system instead of manually replicated in the settings.