20

I have two Java projects in an Eclipse workspace, and I would like to use a class from one of them in the other.

How can I add a reference between them? I'm looking for something like adding a project reference in C#.

3
  • 6
    There's no such thing as a "java project". What tools are you using? Commented Jan 25, 2011 at 20:55
  • 3
    If the OP is using Eclipse there is such thing as a "Java Project" Commented Jan 25, 2011 at 20:57
  • 1
    @Aaron Eclipse isn't Java and Java isn't Eclipse. A lot of people use other tools. Commented Jan 25, 2011 at 20:58

2 Answers 2

28

Assuming you are using Eclipse...

Right click the project -> Properties -> Java Build Path -> Projects tab

...which will allow you to force required projects on the project in questions build path.

Sign up to request clarification or add additional context in comments.

4 Comments

You can also Add Class Folder in Java Build Path if you don't need to add the whole project.
Very new to eclipse :) very old at .NET :) Thanks!!! I also noticed that if I use the class it automatically adds it for you... Nice!
What does this actually do? What files is it changing. Update pls.
Not working. Why?
-1

I had the same problem but even after adding the project in the aforementioned way it still would not recognize the other project.

Turns out you must create a package, not use "default package" in the inner project, that fixed it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.