I'm trying to run the first json-simple example from this page https://code.google.com/p/json-simple/wiki/EncodingExamples in my project.
I've added a maven dependency in my pom.xml from this page http://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple/1.1.1
Intellij IDEA says that everything is fine, dependency is successfully imported. However, it cannot find any json-simple classes in the editor, saying "Cannot resolve symbol 'JSONObject'.
What can be wrong? I had similar issues with adding other dependencies, but i could "solve" them by downloading the necessary jar and adding it as a dependency without using maven.
Appreciate any help
Thank you
If the dependencies weren't imported correctly (IntelliJ IDEA highlights them), try to perform the following actions: You can check your local maven repository in the Maven | Repositories settings and try to update it. You can check the jar file of the local . m2 repository to see if it was downloaded correctly.
Click Run -> Edit Configurations -> Press + -> Search for "Maven" -> Locate "Command Line" field and enter in following maven commands "clean install" -> Press OK. Now click the green button to run that Run/Debug Configuration, this will maven clean install the module/project.
I solve this problem by adding
<scope>compile</scope>
to my missing dependency. It seems that compile
is not always the default.
Strangely while IntelliJ was complaining, Eclipse was able to find the definition.
I'm also having a lot of issues with IntelliJ and dependencies. I'm gonna share some of my trouble shooting methods for it:
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:
It's quick and easy and sometimes that's exactly what's neccessary.
Sometimes the sources haven't been properly generated, then this is the key.
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.
this solution worked for me after trying numerous things:
File -> Invalidate Caches/Restart
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With