You can create dependency between these projects (Make project B dependent on project A) What it does is essentially compiles project A first then put its compiled jar as dependency to Project B for compiling or running.
You can do this manually also.
Steps in IDEA ( You won’t need these below steps if you follow below mentioned best practices):
- Right click on project and select open module settings
- Go to dependencies tab
- click plus sign and add the module you want to use.
Best practices:
- Never use project class in another project, always create a nice interface and use that interface in other projects.
- If possible use Dependency Injection to manage different projects and their dependencies (this internally uses interfaces to do this)
- Use build tool like ant/maven/ivy etc to manage build process.
- Enjoy 🙂