28

I am using:

  • emacs 24.3.1
  • Fedora 20
  • jdk1.7.0_45

I have created a Java project using emacs and have the following project and classpath files:

.project

<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>snaprequest</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription> 

.classpath

<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path="bin"/> </classpath> 

I have this version

In my Java program I want to use the JSONObject so I tried to import the following:

import org.json.JSONObject; 

And when I try and compile on the command line I get this error:

 error: package org.json does not exist import org.json.JSONObject; 

I know I need to add something on my classpath so it can find the jar files, but I am not sure how?

1
  • better to use dependency manager like maven, or google for "how to add external jar in build path eclipse" Commented Jun 16, 2014 at 4:43

2 Answers 2

18

In my case i was using maven build tool and got this error so had to add below dependency from here like below and error resolved.

<dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20180130</version> </dependency> 
Sign up to request clarification or add additional context in comments.

Comments

15

Class org.json.JSONObject is available in json-20131018.jar. You need to download this jar and add this jar to your buildpath.

In order to add external jar to buildpath you can - right click on your project in eclipse - click build path -> configure build path - goto tab libraries - there you will find to add external JAR

This will allow you to include any external jar into your build path.

3 Comments

Actually I am not using eclipse I am using emacs. I was thinking there was a way to edit my .classpath so that when I use javac it will check the classpath and find the jar files that I need. I have downloaded json-simple-1.1.1.jar and need to use that in my project. Thanks.
@MLProgrammer-CiM WHat to do next after adding this dependency in pom.xml ?
This is working for me. I got this json-20131018.jar file from this URL. jar-download.com/artifacts/org.json/json/20131018/source-code

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.