47

I have installed eclipse ide for EE developers and I am receiving an import error for

import javax.json.Json;
import javax.json.JsonReader;
etc.

I have right clicked on project folder -> clicked properties -> clicked Java build path -> add library -> JRE System Library,

but the dependencies that show up are already imported. How can I import the javax.json package?

user1876508
  • 12,864
  • 21
  • 68
  • 105

5 Answers5

49

If using Maven, add this dependency to your pom.xml

<dependency>
    <groupId>javax.json</groupId>
    <artifactId>javax.json-api</artifactId>
    <version>1.0</version>
</dependency>

For Gradle, add this to your build.gradle

compile 'javax.json:javax.json-api:1.0'
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
user2601995
  • 6,463
  • 8
  • 37
  • 41
  • Maven comes configured in [Spring Tool Suite](http://www.springsource.org/sts). Then File > New > Maven Project – user2601995 Aug 21 '13 at 00:00
  • 2
    If I just want to convert my existing project to maven http://stackoverflow.com/questions/2449461/convert-existing-eclipse-project-to-maven-project – user1876508 Aug 21 '13 at 14:24
  • 4
    To get the updated version 1.0.4 of this, use `org.glassfish:javax.json:1.0.4` instead. – Rörd Jul 07 '16 at 13:27
34

Going to assume that you are not using Java 7 and thus need to add the JAR file directly to your project path:

Here's the link to the JAR

And where it came from: http://jsonp.java.net/

Download and add to your project build path.

dispake
  • 3,259
  • 2
  • 19
  • 22
7

You need to get a hold of the Jar from https://java.net/projects/jsonp/

Then got to project folder -> clicked properties -> clicked Java build path -> Add External Jars...

From here you can import the downloaded Jar (library) into your project.

Mark R
  • 416
  • 2
  • 9
1

Using javax.json group (what is in the accepted version) doesn't work for me. I get this:

javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found

Instead, what does work for me is the following (put this in the dependencies section of build.gradle if you're using Gradle):

implementation "org.glassfish:javax.json:1.1.4"

To find the latest version of the library, see the library's search.maven.org page.

Rok Povsic
  • 4,626
  • 5
  • 37
  • 53
0

You will have to download the Jar from https://java.net/projects/jsonp/ as they are not yet part of main Java runtime, download the jar and add it to your classpath and it should work

JSR http://jcp.org/en/jsr/detail?id=353

Mehul Rathod
  • 1,244
  • 8
  • 7