How do I use classes from another project in IntelliJ IDEA?

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):

  1. Right click on project and select open module settings
  2. Go to dependencies tab
  3. click plus sign and add the module you want to use.

Best practices:

  1. Never use project class in another project, always create a nice interface and use that interface in other projects.
  2. If possible use Dependency Injection to manage different projects and their dependencies (this internally uses interfaces to do this)
  3. Use build tool like ant/maven/ivy etc to manage build process.
  4. Enjoy 🙂

Leave a Comment

tech