I find a related question here- java how to use classes in other package?
But, in my case, I want Class A of ProjectA to be used in ClassB of Project B. Project A and Project B are located in different eclipse workspaces or two different folders.
Is this possible, without putting both projects in one folder?
You can import a existing project to your project without copy it into your workspace folder. So ProjectB will be in another folder but you can use it in your workspace.
You can create a jar of Project A and use it in Project B. Then use Class A of Project A in ClassB of project B.
Also you can import project A folder in classpath of Project B to use Class in Class B. Hope this helps.
Got a nice solution. Use maven dependency!
In Project B's pom.xml, add dependency for Project A.
<dependencies>
<dependency>
<groupId>GroupId of Project A</groupId> //can be copied from Project A's POM
<artifactId>Artifact Id of Project A</artifactId> //can be copied from Project A's POM
<version>Version of Project A</version> //can be copied from Project A's POM
</dependency>
</dependencies>
This worked in my case, since both my projects are Maven projects.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.