Right click on the project in which you want to put jar file. A window will open like this

Click on the AddExternal Jars there you can give the path to that jar file

Answer from Ram kiran Pachigolla on Stack Overflow
🌐
Blogger
javarevisited.blogspot.com › 2016 › 07 › eclipse-how-to-add-external-jar-into-classpath.html
Eclipse - How to add/remove external JAR into Java Project's Classpath? Example
May 17, 2023 - That's all about how to add/remove JAR files into your project's classpath in Eclipse. If you are using Maven with Eclipse e.g. via the M2Eclipse plugin then you don't need to do this exercise, as Maven dependencies are always in the build path. You just need to add the new library to the pom.xml and Maven will download and add into Maven dependency automatically. Further Learning Beginners Eclipse Java IDE Training Course Eclipse Debugging Techniques And Tricks The Eclipse Guided Tour - Part 1 and 2 Other Eclipse tutorials and tips for Java Programmers
🌐
Reddit
reddit.com › r/java › how do i add jar files to classpath? specifically, i am using eclipse and i want to add quartz scheduler jar files
r/java on Reddit: How do I add jar files to classpath? Specifically, I am using Eclipse and I want to add Quartz scheduler jar files
February 3, 2014 - In Eclipse: Right click your project, select Build Path > Configure Build Path... Tab over to Libraries · Add external JARs... > Find the JAR you're looking for · Should be good to go.
🌐
Java67
java67.com › 2017 › 04 › how-to-add-jar-file-in-eclipse-project.html
How to add JAR files in Eclipse Project's Build path? Example | Java67
In this Java Eclipse tutorial, ... files in Eclipse Java projects. Many times we need to use external JAR files in our Java application for different needs like for general purposes you may use Google Guava or Apache Commons. If you are using Spring or Hibernate framework then you need their JAR files as well. In order to use any third-party library or framework, we have to add their JAR files in the classpath, to compile ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-add-jar-file-to-classpath-in-java
How to Add JAR file to Classpath in Java? - GeeksforGeeks
August 7, 2021 - Command 2: By including name of JAR file in -a classpath command-line option · This option is viable when we are passing -classpath option while running our java program like java -classpath $(CLASSPATH) Main.
Find elsewhere
🌐
Coderanch
coderanch.com › t › 105951 › ide › include-jar-files-classpath-eclipse
how to include jar files in classpath (eclipse +Quartz Scheduler) (IDEs and Version Control forum at Coderanch)
You should have a left pane in the Java perspective with the name of your project and all the classes in. Right-click the name of the project, then -> properties ... Then I think you just click all the "OK" boxes until you get back to the editor.If you need to add those jars to the finished ...
Top answer
1 of 10
97

Update for latest version

Pre-requisite: In VS Code you need to open the folder and not just file to include any jar file for compilation, running, debugging and testing

VSCode works fine with maven or gradle, and if we are using any of those, we should use maven or gradle for dependency management.

If you are not using any dependency management, then there are two options to add jar file

Option 1: Manually

Open .vscode/settings.json file (if not present, you can create one) and add required jar file there as shown below. In this case all the jar files present in lib directory will be included + I have added common-logging-1.1.1.jar which is located outside the project directory

{
    "java.project.referencedLibraries": [
        "lib/**/*.jar",
        "c:\\path\\to\\jarfile\\commons-logging-1.1.1.jar"
    ]
}

Option 2: Via User Interface

If Java Extension is enabled then on left panel there will be Java Dependencies. Inside there you can click on + symbol to add customer jar files. With this method too, the settings.json file will be updated

Old Answer kept for reference...

VSCode works fine with maven or gradle. But without those, as far as I know they have not provided any direct way to add jar file in classpath.

The workaround is to add the entry in .classpath file manually.

For e.g. in below file I have added common-logging-1.2.jar located in lib directory manually by adding a line <classpathentry exported="true" kind="lib" path="lib/commons-logging-1.2.jar"/>

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="output" path="bin"/>
        <classpathentry exported="true" kind="lib" path="lib/commons-logging-1.2.jar"/>
</classpath>

Update

Finally VSCode team is working towards a better solution. This is still work in progress, but you can refer to this link for better aproach https://github.com/microsoft/vscode-java-pack/issues/94#issuecomment-573487982

Update April 2020

VSCode Extension update now supports this feature out of the box. Now VS Code Java lets you work with JAR files directly without any build tools. Go to JAVA DEPENDENCIES view, find the Referenced Libraries node and click the + icon.

Reference https://github.com/microsoft/vscode-java-pack/blob/master/release-notes/v0.9.0.md#work-with-jar-files-directly

2 of 10
12

Follow these steps in vscode(2022)

Make sure Extension Pack for Java is installed

Install Extension Pack for Java, you may need to restart the vscode.

Project Structure

Create the following

.vscode/
 | -- settings.json
bin/
lib/ <-- Add here all the .jar files 
src/ <-- Add here you java source code

So that the project structure should look like this

Add settings to settings.json

{
    "java.project.sourcePaths": [
        "src"
    ],
    "java.project.outputPath": "bin",
    "java.project.referencedLibraries": [
        "lib/**/*.jar",
    ]
}

  • { "java.project.sourcePaths": [ "src" ], "java.project.outputPath": "bin", "java.project.referencedLibraries": [ "lib/**/*.jar", ] }

  • java.project.sourcePaths: Path of your java source code

  • java.project.outputPath Binary output

  • java.project.referencedLibraries: The .jar files

Now, restart vscode and also if you still have error you many need to Clear file content cache in Visual Studio Code

Also you should see now the library in the Referenced Libraries list. (Note: this may be updated in future vscode version, like name, position and so on)

🌐
Wikihow
wikihow.com › computers and electronics › software › programming › java › how to add jars to project build paths in eclipse (java)
How to Add JARs to Project Build Paths in Eclipse (Java)
August 10, 2022 - This closes the build path setup dialog. If you share the project with someone else, they must also define the variable. They can define it under Window->Preferences->Java->Build Path->Classpath Variables.
🌐
Baeldung
baeldung.com › home › java › jvm › ways to add jars to classpath in java
Ways to Add JARs to Classpath in Java | Baeldung
July 19, 2025 - We can easily add JAR files to our project’s classpath using popular IDEs like Eclipse or IntelliJ.
Top answer
1 of 1
7

The question is a bit unclear, so my answer is equally general...

In order to use a third-party library in Java (like JSON-lib in your case), the library must be present during compilation and during execution (runtime) of your program. This is done by downloading the .jar file and telling Java where to find it. Java uses the concept of classpath:

Classpath is a parameter – set either on the command-line, or through an environment variable – that tells the Java Virtual Machine or the compiler where to look for user-defined classes and packages.

(from Wikipedia)

The error you mention ("Import org.json.JSONObject cannot be resolved") means that the .jar wasn't on the classpath during compilation.

To add a third-party library in Eclipse, store the .jar file somewhere in your project (a dedicated lib folder would be a good choice), then right-click on your project, choose Properties → Java Build Path → Libraries, click "Add JARs..." and choose your .jar file. From now on, Eclipse will add it to the classpath during compilation.

Adding it to the classpath during execution depends on the kind of project you're running. If you have a simple main method which you're running from Eclipse, the .jar will be automatically added to the classpath. If you're running a web application in a container such as Tomcat, JBoss etc., then the standard way to add the .jar to the classpath would be to put it in the WEB-INF/lib directory of your deployed application. Have a look at the Java EE tutorial for more information on web applications and their deployment.

🌐
Wikitechy
wikitechy.com › tutorials › java › how-to-add-jar-file-to-classpath-in-java
How to add JAR file to Classpath in Java - By Microsoft Awarded MVP - Learn in 30sec | wikitechy
Java 6 wildcard is preferred way of adding multiple JAR in class path along with -cp and -classpath command line option. In the event that you are working in multiple OS than it is too fine to recall that two directories in classpath are divided using semi colon (;) in windows based systems and in UNIX based system colon (:) is used. ... add jar to classpath eclipseadd jar to classpath intellijadd jar to classpath netbeansadd jar to classpath linuxjava add jar to classpath command lineadd jar to classpath mavenadd jar to classpath macadd jar to classpath environment variablehow to add jar file in eclipse java projecthow to import jar file in java codereferenced libraries eclipseadd jar to classpath windowshow to set classpath in eclipse for javahow to import executable jar file in eclipse
🌐
Gradle
discuss.gradle.org › help/discuss › buildship
A .jar added to the Eclipse classpath is missing at runtime - Buildship - Gradle Forums
April 13, 2018 - I am trying to insert a .jar file onto the classpath in Eclipse only. (Don’t ask!) It seems to only get onto the compile classpath. It builds, but when launching with Run, or Run as JUnit it is missing and crashes. The relevant bits are: subprojects { configurations { parserSubstitution } dependencies { parserSubstitution module("com.example:parser:1.0.0-SNAPSHOT") } apply plugin: 'eclipse' eclipse { classpath { plusConfigurations ...
🌐
Stack Overflow
stackoverflow.com › questions › 26103954 › how-to-add-a-jar-to-the-classpath-in-eclipse
java - How to add a jar to the classpath in eclipse - Stack Overflow
September 29, 2014 - Add the jar in source dir or project folder then select in eclipse, right-click will give you to add the jar in classpath
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Include Jars In Java Classpath Example - Java Code Geeks
February 13, 2025 - Run the Java program as usual without specifying the JAR in the classpath · However, this mechanism was removed in Java 9 due to security and modularization improvements introduced by Project Jigsaw. For modern Java versions, consider using explicit classpath settings or dependency management tools like Maven or Gradle. Modern IDEs like Eclipse and IntelliJ IDEA provide built-in mechanisms to easily add JAR files to your project’s classpath.