âšī¸ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.1 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://howtodoinjava.com/java-examples/set-classpath-command-line/ |
| Last Crawled | 2026-04-11 07:23:56 (2 days ago) |
| First Indexed | 2020-08-05 02:51:39 (5 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Java - Set Classpath from Command Line |
| Meta Description | Learn to use the -classpath or -cp option in command prompt to set classpath from command prompt in Windows and Linux OS. |
| Meta Canonical | null |
| Boilerpipe Text | Learn to use the
-classpath
or
-cp
option to
set the Java classpath
from the
command prompt
in Windows and Linux OS.
1. Java Classpath
The
classpath is the list of directory locations
that the Java runtime environment searches for the classes and other resource files, during program execution.
The
default classpath is the current working directory
.
Setting the
CLASSPATH
environment variable or using the
-classpath
command-line option overrides the default value.
If we want to
include the current working directory in the classpath
, we must include
"."
(dot or period character) in the list of paths.
The
value of classpath set from the command prompt is temporary
and is not available if we open a new command prompt.
If we want to
set the classpath permanently
then we should set the
classpath as environment variable in Windows
. In Linux, set the value in
bash profile
.
Path Separators are Platform Dependent
The separator between two paths in the classpath value is platform-dependent.
In Windows, the path separator is semicolon ( ; ) and the path separator in Linux is colon (
:
).
2. Setting Classpath from Command Line
There are two ways :
Use
-classpath
or
-cp
option to provide the classpath locations while starting the Java application or tool.
java -cp
.
;
c:/jars demo-application.jar
Use
set CLASSPATH
command initially, and then run Java application or tool in the same command line window. â
It will search the classes/resources in mentioned classpath locations.
Classpath entries that are neither directories nor archives (.zip or .jar files) nor
*
are ignored.
set
CLASSPATH
.
;
c:/jars
The above examples are specific to Windows. Please use
colon
as the path separator for Linux.
3. Wildcards in Classpath
Generally, we will include two kinds of resources in classpath i.e. classes and jar files.
To
include classes
, give the complete path of the folder where classes are present.
.
(dot) represent the current directory.
To
include jar files
, give the complete path of the folder where jars are present. Add a star (
*
) wildcard for adding all jar files in that directory.
Please note that the jar
files present in the sub-directories are NOT included automatically
. Sub-folders must be included explicitely.
java -cp c:/temp/lib applation.jar //includes all classes
in
the directory
'c:/temp/lib'
java -cp c:/temp/lib/* application.jar //includes all jars
in
the directory
'c:/temp/lib'
java -cp c:/temp/lib
;
c:/temp/lib/* application.jar //includes all classes and jars
4. How to Clear Classpath Value
To unset a classpath value previously set, use this command to clear its value using am empty value assigned to the variable.
set
CLASSPATH
=
Happy Learning !! |
| Markdown | âī¸
[Skip to content](https://howtodoinjava.com/java-examples/set-classpath-command-line/#content "Skip to content")
[](https://howtodoinjava.com/)
Menu
Menu
- [Java](https://howtodoinjava.com/java/basics/java-tutorial/)
- [Spring AI](https://howtodoinjava.com/series/spring-ai-tutorial/)
- [Spring Boot](https://howtodoinjava.com/spring-boot/spring-boot/)
- [Hibernate](https://howtodoinjava.com/hibernate/hibernate-tutorials/)
- [JUnit 5](https://howtodoinjava.com/junit5/junit/)
- [Interview](https://howtodoinjava.com/interview-questions/interview-guides/)
# Java â Set Classpath from Command Line
Learn to use the -classpath or -cp option to set the Java classpath from the command prompt in Windows and Linux OS. 1. Java Classpath The classpath is the list of directory locations that the Java runtime environment searches for the classes and other resource files, during program âĻ
[Lokesh Gupta](https://howtodoinjava.com/author/lokeshgupta/)
January 25, 2022
[Java Examples](https://howtodoinjava.com/java-examples/)
[Command Line Arguments](https://howtodoinjava.com/tag/command-line-arguments/), [Java Classpath](https://howtodoinjava.com/tag/java-classpath/)

Learn to use the **\-classpath** or **\-cp** option to *set the Java classpath* from the **command prompt** in Windows and Linux OS.
## 1\. Java Classpath
- The *classpath is the list of directory locations* that the Java runtime environment searches for the classes and other resource files, during program execution.
- The **default classpath is the current working directory**.
- Setting the `CLASSPATH` environment variable or using the `-classpath` command-line option overrides the default value.
- If we want to **include the current working directory in the classpath**, we must include `"."` (dot or period character) in the list of paths.
- The *value of classpath set from the command prompt is temporary* and is not available if we open a new command prompt.
- If we want to **set the classpath permanently** then we should set the [classpath as environment variable in Windows](https://howtodoinjava.com/java/basics/java-classpath/). In Linux, set the value in [bash profile](https://superuser.com/questions/678113/how-to-add-a-line-to-bash-profile).
#### Path Separators are Platform Dependent
The separator between two paths in the classpath value is platform-dependent.
In Windows, the path separator is semicolon ( ; ) and the path separator in Linux is colon ( `:` ).
## 2\. Setting Classpath from Command Line
There are two ways :
- Use `-classpath` or `-cp` option to provide the classpath locations while starting the Java application or tool.
```
java -cp .;c:/jars demo-application.jar
```
- Use `set CLASSPATH` command initially, and then run Java application or tool in the same command line window. â
It will search the classes/resources in mentioned classpath locations.
Classpath entries that are neither directories nor archives (.zip or .jar files) nor `*` are ignored.
```
set CLASSPATH .;c:/jars
```
The above examples are specific to Windows. Please use *colon* as the path separator for Linux.
## 3\. Wildcards in Classpath
Generally, we will include two kinds of resources in classpath i.e. classes and jar files.
- To **include classes**, give the complete path of the folder where classes are present. `.` (dot) represent the current directory.
- To **include jar files**, give the complete path of the folder where jars are present. Add a star (`*`) wildcard for adding all jar files in that directory.
> Please note that the jar **files present in the sub-directories are NOT included automatically**. Sub-folders must be included explicitely.
```
```
## 4\. How to Clear Classpath Value
To unset a classpath value previously set, use this command to clear its value using am empty value assigned to the variable.
```
set CLASSPATH=
```
Happy Learning !\!
### Comments
Subscribe
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Load More Comments
## Java Examples
- [Convert String to int](https://howtodoinjava.com/java/string/convert-string-to-int/)
- [Get Current Working Directory](https://howtodoinjava.com/java/io/get-current-working-directory/)
- [Convert String to byte\[\]](https://howtodoinjava.com/java/array/convert-byte-array-string/)
- [Convert Hex to ASCII](https://howtodoinjava.com/java/convert-hex-to-ascii-and-ascii-to-hex/)
- [Generate Random Numbers](https://howtodoinjava.com/java/generate-random-numbers/)
- [Calculate Age from Date of Birth](https://howtodoinjava.com/java/calculate-age-from-date-of-birth/)
- [Binary, Octal & Hexadecimal Conversions](https://howtodoinjava.com/java/binary-octal-and-hexadecimal-conversions-in-java/)
## Table of Contents
- [1\. Java Classpath](https://howtodoinjava.com/java-examples/set-classpath-command-line/#1-java-classpath)
- - [Path Separators are Platform Dependent](https://howtodoinjava.com/java-examples/set-classpath-command-line/#path-separators-are-platform-dependent)
- [2\. Setting Classpath from Command Line](https://howtodoinjava.com/java-examples/set-classpath-command-line/#2-setting-classpath-from-command-line)
- [3\. Wildcards in Classpath](https://howtodoinjava.com/java-examples/set-classpath-command-line/#3-wildcards-in-classpath)
- [4\. How to Clear Classpath Value](https://howtodoinjava.com/java-examples/set-classpath-command-line/#4-how-to-clear-classpath-value)

Lokesh Gupta
A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies. An avid Sci-Fi movie enthusiast and a fan of Christopher Nolan and Quentin Tarantino.
[Follow on Twitter](https://x.com/HowToDoInJava)
[Portfolio](https://lokeshgupta.me/)
Previous
### [Spring Boot Kafka Multiple Consumers Example](https://howtodoinjava.com/kafka/multiple-consumers-example/)
Next
### [Reading a File from Classpath in Java](https://howtodoinjava.com/java/io/read-file-from-classpath/)
#### About Us
*HowToDoInJava* provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.
#### Tutorial Series
[OOP](https://howtodoinjava.com/java/oops/oop-tutorials/)
[Regex](https://howtodoinjava.com/java/regex/java-regex/)
[Maven](https://howtodoinjava.com/maven/maven-tutorials/)
[Logging](https://howtodoinjava.com/log4j2/java-logging/)
[TypeScript](https://howtodoinjava.com/typescript/typescript-tutorial/)
[Python](https://howtodoinjava.com/python-tutorial/)
#### Meta Links
[About Us](https://howtodoinjava.com/about/)
[Advertise](https://howtodoinjava.com/advertise/)
[Contact Us](https://howtodoinjava.com/contact/)
[Privacy Policy](https://howtodoinjava.com/privacy-policy/)
#### Our Blogs
[REST API Tutorial](https://restfulapi.net/)
#### Follow On:
- [Github](https://github.com/lokeshgupta1981/)
- [LinkedIn](https://www.linkedin.com/in/lokeshgupta1981/)
- [Twitter](https://twitter.com/howtodoinjava)
- [Facebook](https://facebook.com/howtodoinjava)
Copyright Š 2026 \| [Sitemap](https://howtodoinjava.com/sitemap.xml)
Insert |
| Readable Markdown | Learn to use the **\-classpath** or **\-cp** option to *set the Java classpath* from the **command prompt** in Windows and Linux OS.
## 1\. Java Classpath
- The *classpath is the list of directory locations* that the Java runtime environment searches for the classes and other resource files, during program execution.
- The **default classpath is the current working directory**.
- Setting the `CLASSPATH` environment variable or using the `-classpath` command-line option overrides the default value.
- If we want to **include the current working directory in the classpath**, we must include `"."` (dot or period character) in the list of paths.
- The *value of classpath set from the command prompt is temporary* and is not available if we open a new command prompt.
- If we want to **set the classpath permanently** then we should set the [classpath as environment variable in Windows](https://howtodoinjava.com/java/basics/java-classpath/). In Linux, set the value in [bash profile](https://superuser.com/questions/678113/how-to-add-a-line-to-bash-profile).
#### Path Separators are Platform Dependent
The separator between two paths in the classpath value is platform-dependent.
In Windows, the path separator is semicolon ( ; ) and the path separator in Linux is colon ( `:` ).
## 2\. Setting Classpath from Command Line
There are two ways :
- Use `-classpath` or `-cp` option to provide the classpath locations while starting the Java application or tool.
- Use `set CLASSPATH` command initially, and then run Java application or tool in the same command line window. â
It will search the classes/resources in mentioned classpath locations.
Classpath entries that are neither directories nor archives (.zip or .jar files) nor `*` are ignored.
The above examples are specific to Windows. Please use *colon* as the path separator for Linux.
## 3\. Wildcards in Classpath
Generally, we will include two kinds of resources in classpath i.e. classes and jar files.
- To **include classes**, give the complete path of the folder where classes are present. `.` (dot) represent the current directory.
- To **include jar files**, give the complete path of the folder where jars are present. Add a star (`*`) wildcard for adding all jar files in that directory.
> Please note that the jar **files present in the sub-directories are NOT included automatically**. Sub-folders must be included explicitely.
## 4\. How to Clear Classpath Value
To unset a classpath value previously set, use this command to clear its value using am empty value assigned to the variable.
Happy Learning !\! |
| Shard | 75 (laksa) |
| Root Hash | 11080523165406572475 |
| Unparsed URL | com,howtodoinjava!/java-examples/set-classpath-command-line/ s443 |