1

I am trying to write a program in Java using Maven in IntelliJ which calls an API using HttpURLConnection and parses the response using JSONArray and JSONObject. I have attempted to import the org.json JAR file, and I've updated my pom.xml to include it as a dependency, but I'm still getting the following error.

Test.java:1: error: package org.json does not exist
import org.json.JSONArray;

pom.xml:

<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20210307</version>
</dependency>

I have also tried adding the downloaded JAR file to Project Structure > Modules > Dependencies but have had no luck. Is there something else I could be overlooking here?

Luke
  • 11
  • 1
  • 2
  • Have you reimported Maven after adding a dependency to pom.xml? https://www.jetbrains.com/help/idea/delegate-build-and-run-actions-to-maven.html#maven_reimport – Egor Klepikov Jul 12 '21 at 14:24

1 Answers1

2

Your dependency and import looks correct. Reloading all maven dependencies should resolve the issue. Check this post out: Force Intellij IDEA to reread all maven dependencies

jwanger
  • 74
  • 7