Intellij IDEA can't find a class in successfully imported Maven dependency
I'm also having a lot of issues with IntelliJ and dependencies. I'm gonna share some of my trouble shooting methods for it:
- Make sure that the
pom.xml
has the dependencies in it.
This is the very first thing to do, and I assume you've already done it.
For the next step you can either use the maven tab on the right:
which looks like this when you click it:
or right click your pom.xml
and pick Maven
like so:
- Reimport
It's quick and easy and sometimes that's exactly what's neccessary.
- Generate sources and Update Folders
Sometimes the sources haven't been properly generated, then this is the key.
- Download Sources
Sometimes IntelliJ doesn't do this automatically, something you can change in Settings > Build, Execution, Deployment > Build tools > Maven > Importing
and enable Import Maven projects automativally
.
The download Sources looks like this:
The settings button is the one furthest on the right on my example images of the Maven tab.
Last but not least:
Put your cursor on the red part of the import, (the import org.json.simple.JSONObject;
part) wait for the red lamp to appear, and the choose "add to class path".
When all else is as it should, the class path needs to be updated with your import. IntelliJ doesn't always do this automatically either.