Intellij IDEA cannot find class in successfully imported Maven dependency

I am trying to run the first json-simple example from this page https://code.google.com/p/json-simple/wiki/EncodingExamples in my project.

I added the 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 in order, the dependency has been successfully imported. However, in the editor he cannot find json-simple classes saying: "Cannot resolve the" JSONObject "character. enter image description here

What could be wrong? I had similar problems with adding other dependencies, but I could "solve" them by loading the necessary jar and adding it as a dependency without using maven.

Appreciate any help

thanks

+8
intellij-idea maven
source share
2 answers

I also have a lot of problems with IntelliJ and dependencies. I am going to share some of my problem-solving methods:

  • Make sure pom.xml has dependencies in it.

This is the first thing to do, and I assume that you have already done it.

For the next step, you can either use the maven tab on the right:

enter image description here

which looks like this when you click it:

enter image description here

or right-click on pom.xml and select Maven like this:

enter image description here

  1. Reimport

It is quick and easy, and sometimes what is needed.

enter image description here

  1. Creating sources and updating folders

Sometimes the sources were not correctly generated, then this is the key.

enter image description here

  1. Download Source

Sometimes IntelliJ does not do this automatically, something that you can change in Settings > Build, Execution, Deployment > Build tools > Maven > Importing and enable Import Maven projects automativally .

Download sources are as follows:

enter image description here

The settings button is the farthest to the right of my Maven tab image examples.

And last but not least:

Place the cursor on the red part of the import (part of import org. json .simple.JSONObject; ) until the red light appears, and select "add to class path".

When everything else is as it should, the class path should be updated with your import. IntelliJ does not always do this automatically.

+13
source share

I solve this problem by adding

<scope>compile</scope>

to my missing addiction. It seems that compile not always the default value.

Strange when IntelliJ complained, Eclipse was able to find a definition.

+1
source share

All Articles