🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 103 (from laksa064)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
CRAWLED
4 hours ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.geeksforgeeks.org/java/different-ways-to-set-a-classpath-in-java/
Last Crawled2026-04-14 21:50:32 (4 hours ago)
First Indexed2025-06-12 18:20:13 (10 months ago)
HTTP Status Code200
Meta TitleDifferent Ways to Set a Classpath in Java - GeeksforGeeks
Meta DescriptionYour All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more., Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
Meta Canonicalnull
Boilerpipe Text
Last Updated : 23 Jul, 2025 Java Virtual Machine(JVM) uses classpath to locate the class files to execute the code. If your classpath is not set and the class file is not present in the same directory as your java file, then JVM will be unable to find the required class file, and it will throw an error ( java.lang.ClassNotFoundException ). error caused while JVM is interpreting the code Ways to Set a Classpath  There are five different ways to set a classpath. These are: -cp -classpath --classpath Temporary settings by using the 'set classpath' command Permanent settings using environment variable window The limitation of - cp , - classpath, and --class-path methods is that it can set classpath only for the current command line, in the next command line, if we access the desired class directly, we will get an Exception Syntax: >java -cp <directory_location> <class name> Example: // This code is located in F:\workspace\src // It's class file is located in F:\workspace\bin class GFG { public static void main ( String [] args ) { System . out . println ( "GFG!" ); } } how to set classpath by using -cp command Command Line Settings - >java -cp <directory_location> <class name>                  OR >java -classpath <directory_location> <class name>                  OR >java --class-path <directory_location> <class name> If we want to access classpath for all command lines, we must set the classpath command option. The limitation of the "set classpath" command option is the classpath settings are available only for the current command prompt. Temporary Settings: >set classpath=<directory_location> the temporary setting of classpath using 'set classpath' command If we want to have classpath settings permanently for all the command prompts, we must set classpath in the environment variable section.  Permanent Settings: Firstly, Right Click on "This PC". Click Properties. Click "Advanced System Settings". Click "Environment Variables". In the "User Variable Section", click the "New" button. Enter Variable name :classpath [Don't give space between class path] Variable value:<directory_location>(for example in my F:\workspace\bin) Click OK->OK->OK. Close all windows, open a new command prompt, and run the java command Environment Variables Setting permanent classpath settings We must include .; in the classpath beginning so that the JVM can access both the current working directory and the directory of the desired class file, respectively. >java -cp <.;directory_location> <class name> Importance of '.' in the classpath If we set classpath pointing to one directory, if we don't place (dot), the classes available in the current working directory will not be found by compiler and JVM . '.' represents the current working directory. The current working directory means not the folder where you save the .java file, the folder path where you open the command prompt.  Syntax to include multiple paths in the classpath We must separate each folder location with a semicolon separator. java -cp ./folder1/*;./folder2/*;./folder3/* com.xyz.MainClass Note - The algorithm followed by the compiler and JVM for finding classes from classpath is First Come First Execute. Difference between path and classpath searching algorithm priority Command prompt software will give first priority to present the working directory. In the present working directory, if the binary file is unavailable, only consider the path variable. Compiler and JVM first look for classpath. If a classpath is not created, then only they will search in the current working directory. If a classpath is created, they don't look into the current working directory, only the classpath folder. Note - Generally in the Developer community, the first 4 types are recommended, they try to avoid using the permanent settings using the environment variable window. 
Markdown
[![geeksforgeeks](https://media.geeksforgeeks.org/gfg-gg-logo.svg)](https://www.geeksforgeeks.org/) ![search icon](https://media.geeksforgeeks.org/auth-dashboard-uploads/Property=Light---Default.svg) - Sign In - [Courses]() - [Tutorials]() - [Interview Prep]() - [Java Tutorial](https://www.geeksforgeeks.org/java/java/) - [Advanced Java](https://www.geeksforgeeks.org/advance-java/advanced-java/) - [Interview Questions](https://www.geeksforgeeks.org/java/java-interview-questions/) - [Exercises](https://www.geeksforgeeks.org/java/java-exercises/) - [Examples](https://www.geeksforgeeks.org/java/java-programming-examples/) - [Quizzes](https://www.geeksforgeeks.org/java/java-quiz/) - [Projects](https://www.geeksforgeeks.org/blogs/java-projects/) - [Cheatsheet](https://www.geeksforgeeks.org/java/java-cheat-sheet/) - [DSA in Java](https://www.geeksforgeeks.org/dsa/dsa-in-java/) - [Java Collection](https://www.geeksforgeeks.org/java/java-collection-tutorial/) # Different Ways to Set a Classpath in Java Last Updated : 23 Jul, 2025 **Java Virtual Machine(JVM)** uses classpath to locate the class files to execute the code. If your classpath is not set and the class file is not present in the same directory as your java file, then JVM will be unable to find the required class file, and it will throw an error ([java.lang.ClassNotFoundException](https://www.geeksforgeeks.org/java/how-to-solve-java-lang-classnotfoundexception-in-java/)). ![java.lang.ClassNotFoundException](https://media.geeksforgeeks.org/wp-content/uploads/20211002105453/errormsg-300x30.PNG) error caused while JVM is interpreting the code ### Ways to Set a Classpath There are five different ways to set a classpath. These are: - \-cp - \-classpath - \--classpath - Temporary settings by using the 'set classpath' command - Permanent settings using environment variable window The limitation of -**cp**,**\-**classpath, and **\--class-path** methods is that it can set classpath only for the current command line, in the next command line, if we access the desired class directly, we will get an Exception **Syntax:** ``` >java -cp <directory_location> <class name> ``` **Example:** Java `` ![](https://media.geeksforgeeks.org/wp-content/uploads/20211002170323/cpcommand-300x59.PNG) how to set classpath by using -cp command ### Command Line Settings - ``` >java -cp <directory_location> <class name> ``` **OR** ``` >java -classpath <directory_location> <class name> ``` **OR** ``` >java --class-path <directory_location> <class name> ``` - If we want to access classpath for all command lines, we must set the classpath command option. - The limitation of the **"set classpath"** command option is the classpath settings are available only for the current command prompt. ### Temporary Settings: ``` >set classpath=<directory_location> ``` ![](https://media.geeksforgeeks.org/wp-content/uploads/20211002171608/Temporarysettingofclasspath-300x58.PNG) the temporary setting of classpath using 'set classpath' command If we want to have classpath settings permanently for all the command prompts, we must set classpath in the environment variable section. ### Permanent Settings: 1. Firstly, Right Click on "This PC". 2. Click Properties. 3. Click "Advanced System Settings". 4. Click "Environment Variables". 5. In the "User Variable Section", click the "New" button. 6. Enter Variable name :classpath \[Don't give space between class path\] Variable value:\<directory\_location\>(for example in my F:\\workspace\\bin) 7. Click OK-\>OK-\>OK. 8. Close all windows, open a new command prompt, and run the java command ![](https://media.geeksforgeeks.org/wp-content/uploads/20211002172921/Permanentsettings.PNG) Environment Variables Setting ![](https://media.geeksforgeeks.org/wp-content/uploads/20211002172920/permanentclasspathsettings-200x38.PNG) permanent classpath settings ## We must include **.;** in the classpath beginning so that the **JVM** can access both the current working directory and the directory of the desired class file, respectively. ``` >java -cp <.;directory_location> <class name> ``` ### Importance of '.' in the classpath If we set classpath pointing to one directory, if we don't place (dot), the classes available in the current working directory will not be found by compiler and **JVM**. **'.'** represents the current working directory. The current working directory means not the folder where you save the .java file, the folder path where you open the command prompt. ### Syntax to include multiple paths in the classpath We must separate each folder location with a **semicolon** separator. ``` java -cp ./folder1/*;./folder2/*;./folder3/* com.xyz.MainClass ``` > **Note -** The algorithm followed by the compiler and JVM for finding classes from classpath is **First Come First Execute.** ### Difference between path and classpath searching algorithm priority - Command prompt software will give first priority to present the working directory. In the present working directory, if the binary file is unavailable, only consider the path variable. - Compiler and **JVM** first look for classpath. - If a classpath is not created, then only they will search in the current working directory. - If a classpath is created, they don't look into the current working directory, only the classpath folder. > **Note -** Generally in the Developer community, the first 4 types are recommended, they try to avoid using the permanent settings using the environment variable window. Comment [D](https://www.geeksforgeeks.org/user/dasdepesh/) [dasdepesh](https://www.geeksforgeeks.org/user/dasdepesh/) 4 Article Tags: Article Tags: [Java](https://www.geeksforgeeks.org/category/programming-language/java/) [java-basics](https://www.geeksforgeeks.org/tag/java-basics/) ### Explore [![GeeksforGeeks](https://media.geeksforgeeks.org/auth-dashboard-uploads/gfgFooterLogo.png)](https://www.geeksforgeeks.org/) ![location](https://media.geeksforgeeks.org/img-practice/Location-1685004904.svg) Corporate & Communications Address: A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305) ![location](https://media.geeksforgeeks.org/img-practice/Location-1685004904.svg) Registered Address: K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305 [![GFG App on Play Store](https://media.geeksforgeeks.org/auth-dashboard-uploads/googleplay-%281%29.png)](https://geeksforgeeksapp.page.link/gfg-app)[![GFG App on App Store](https://media.geeksforgeeks.org/auth-dashboard-uploads/appstore-%281%29.png)](https://geeksforgeeksapp.page.link/gfg-app) - Company - [About Us](https://www.geeksforgeeks.org/about/) - [Legal](https://www.geeksforgeeks.org/legal/) - [Privacy Policy](https://www.geeksforgeeks.org/legal/privacy-policy/) - [Contact Us](https://www.geeksforgeeks.org/about/contact-us/) - [Advertise with us](https://www.geeksforgeeks.org/advertise-with-us/) - [GFG Corporate Solution](https://www.geeksforgeeks.org/gfg-corporate-solution/) - [Campus Training Program](https://www.geeksforgeeks.org/campus-training-program/) - Explore - [POTD](https://www.geeksforgeeks.org/problem-of-the-day) - [Job-A-Thon](https://practice.geeksforgeeks.org/events/rec/job-a-thon/) - [Blogs](https://www.geeksforgeeks.org/category/blogs/?type=recent) - [Nation Skill Up](https://www.geeksforgeeks.org/nation-skill-up/) - Tutorials - [Programming Languages](https://www.geeksforgeeks.org/computer-science-fundamentals/programming-language-tutorials/) - [DSA](https://www.geeksforgeeks.org/dsa/dsa-tutorial-learn-data-structures-and-algorithms/) - [Web Technology](https://www.geeksforgeeks.org/web-tech/web-technology/) - [AI, ML & Data Science](https://www.geeksforgeeks.org/machine-learning/ai-ml-and-data-science-tutorial-learn-ai-ml-and-data-science/) - [DevOps](https://www.geeksforgeeks.org/devops/devops-tutorial/) - [CS Core Subjects](https://www.geeksforgeeks.org/gate/gate-exam-tutorial/) - [Interview Preparation](https://www.geeksforgeeks.org/aptitude/interview-corner/) - [Software and Tools](https://www.geeksforgeeks.org/websites-apps/software-and-tools-a-to-z-list/) - Courses - [ML and Data Science](https://www.geeksforgeeks.org/courses/category/machine-learning-data-science) - [DSA and Placements](https://www.geeksforgeeks.org/courses/category/dsa-placements) - [Web Development](https://www.geeksforgeeks.org/courses/category/development-testing) - [Programming Languages](https://www.geeksforgeeks.org/courses/category/programming-languages) - [DevOps & Cloud](https://www.geeksforgeeks.org/courses/category/cloud-devops) - [GATE](https://www.geeksforgeeks.org/courses/category/gate) - [Trending Technologies](https://www.geeksforgeeks.org/courses/category/trending-technologies/) - Videos - [DSA](https://www.geeksforgeeks.org/videos/category/sde-sheet/) - [Python](https://www.geeksforgeeks.org/videos/category/python/) - [Java](https://www.geeksforgeeks.org/videos/category/java-w6y5f4/) - [C++](https://www.geeksforgeeks.org/videos/category/c/) - [Web Development](https://www.geeksforgeeks.org/videos/category/web-development/) - [Data Science](https://www.geeksforgeeks.org/videos/category/data-science/) - [CS Subjects](https://www.geeksforgeeks.org/videos/category/cs-subjects/) - Preparation Corner - [Interview Corner](https://www.geeksforgeeks.org/interview-prep/interview-corner/) - [Aptitude](https://www.geeksforgeeks.org/aptitude/aptitude-questions-and-answers/) - [Puzzles](https://www.geeksforgeeks.org/aptitude/puzzles/) - [GfG 160](https://www.geeksforgeeks.org/courses/gfg-160-series) - [System Design](https://www.geeksforgeeks.org/system-design/system-design-tutorial/) [@GeeksforGeeks, Sanchhaya Education Private Limited](https://www.geeksforgeeks.org/), [All rights reserved](https://www.geeksforgeeks.org/copyright-information/) ![]()
Readable Markdown
Last Updated : 23 Jul, 2025 **Java Virtual Machine(JVM)** uses classpath to locate the class files to execute the code. If your classpath is not set and the class file is not present in the same directory as your java file, then JVM will be unable to find the required class file, and it will throw an error ([java.lang.ClassNotFoundException](https://www.geeksforgeeks.org/java/how-to-solve-java-lang-classnotfoundexception-in-java/)). ![java.lang.ClassNotFoundException](https://media.geeksforgeeks.org/wp-content/uploads/20211002105453/errormsg-300x30.PNG) error caused while JVM is interpreting the code ### Ways to Set a Classpath There are five different ways to set a classpath. These are: - \-cp - \-classpath - \--classpath - Temporary settings by using the 'set classpath' command - Permanent settings using environment variable window The limitation of -**cp**,**\-**classpath, and **\--class-path** methods is that it can set classpath only for the current command line, in the next command line, if we access the desired class directly, we will get an Exception **Syntax:** ``` >java -cp <directory_location> <class name> ``` **Example:** `` ![](https://media.geeksforgeeks.org/wp-content/uploads/20211002170323/cpcommand-300x59.PNG) how to set classpath by using -cp command ### Command Line Settings - ``` >java -cp <directory_location> <class name> ``` **OR** ``` >java -classpath <directory_location> <class name> ``` **OR** ``` >java --class-path <directory_location> <class name> ``` - If we want to access classpath for all command lines, we must set the classpath command option. - The limitation of the **"set classpath"** command option is the classpath settings are available only for the current command prompt. ### Temporary Settings: ``` >set classpath=<directory_location> ``` ![](https://media.geeksforgeeks.org/wp-content/uploads/20211002171608/Temporarysettingofclasspath-300x58.PNG) the temporary setting of classpath using 'set classpath' command If we want to have classpath settings permanently for all the command prompts, we must set classpath in the environment variable section. ### Permanent Settings: 1. Firstly, Right Click on "This PC". 2. Click Properties. 3. Click "Advanced System Settings". 4. Click "Environment Variables". 5. In the "User Variable Section", click the "New" button. 6. Enter Variable name :classpath \[Don't give space between class path\] Variable value:\<directory\_location\>(for example in my F:\\workspace\\bin) 7. Click OK-\>OK-\>OK. 8. Close all windows, open a new command prompt, and run the java command ![](https://media.geeksforgeeks.org/wp-content/uploads/20211002172921/Permanentsettings.PNG) Environment Variables Setting ![](https://media.geeksforgeeks.org/wp-content/uploads/20211002172920/permanentclasspathsettings-200x38.PNG) permanent classpath settings We must include **.;** in the classpath beginning so that the **JVM** can access both the current working directory and the directory of the desired class file, respectively. ``` >java -cp <.;directory_location> <class name> ``` ### Importance of '.' in the classpath If we set classpath pointing to one directory, if we don't place (dot), the classes available in the current working directory will not be found by compiler and **JVM**. **'.'** represents the current working directory. The current working directory means not the folder where you save the .java file, the folder path where you open the command prompt. ### Syntax to include multiple paths in the classpath We must separate each folder location with a **semicolon** separator. ``` java -cp ./folder1/*;./folder2/*;./folder3/* com.xyz.MainClass ``` > **Note -** The algorithm followed by the compiler and JVM for finding classes from classpath is **First Come First Execute.** ### Difference between path and classpath searching algorithm priority - Command prompt software will give first priority to present the working directory. In the present working directory, if the binary file is unavailable, only consider the path variable. - Compiler and **JVM** first look for classpath. - If a classpath is not created, then only they will search in the current working directory. - If a classpath is created, they don't look into the current working directory, only the classpath folder. > **Note -** Generally in the Developer community, the first 4 types are recommended, they try to avoid using the permanent settings using the environment variable window.
Shard103 (laksa)
Root Hash12046344915360636903
Unparsed URLorg,geeksforgeeks!www,/java/different-ways-to-set-a-classpath-in-java/ s443