As per my understanding you want to change the classpath which you have set by command
set classpath=d:java

can be done in two ways either you can set classpth directly as environment varible by
--> Right click on my computer select advanced options
--> there you will see option as environment variables open that option
--> now you will see multiple variables being set...search for classpath variable if it exist their edit this variable value by just putting semicolon and write ur full classpath ended by semicolon and save it.
FOR EG:-

variable name:- CLASSAPTH
variable value- .;C:\Oracle\product\10.1.0\Client_2\jdbc\lib\ojdbc14.jar;

Second option is just set your class in command promt as u have set earlier

by opening command prompt

set classpath=C:\Oracle\product\10.1.0\Client_2\jdbc\lib\ojdbc14.jar;

both the method are easy but i would prefer you should go with first one as by doing that you didn't need to set your classpath again and again after you reboot your system or application.

Answer from Mukund Jindal on Stack Overflow
🌐
HowToDoInJava
howtodoinjava.com › home › java examples › java – set classpath from command line
Java - Set Classpath from Command Line
January 25, 2022 - Learn to use the -classpath or -cp option to set the Java classpath from the command prompt in Windows and Linux OS.
Discussions

java - Setting Classpath using command prompt in Windows 7 - Stack Overflow
Class path entries can contain the basename wildcard character , which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For example, the class path entry foo/ specifies all JAR files in the directory named foo. A classpath entry ... More on stackoverflow.com
🌐 stackoverflow.com
September 14, 2013
Java : How to use a -classpath in the command prompt.
http://www.ibm.com/developerworks/library/j-classpath-windows/ Best article about the topic. Please include the error next time. More on reddit.com
🌐 r/learnprogramming
3
1
August 6, 2015
mysql - Set default classpath to use in `java` command in command prompt - Stack Overflow
What I'm trying to do is running a .java source by compiling and running it from command prompt (not using any IDE) using commands javac and java and the program connects with MySQL, so everytime I run the program from cmd, I need to specify path of the MySQL connector using -classpath switch ... More on stackoverflow.com
🌐 stackoverflow.com
How to write a batch file to set classpath and execute java programs - Stack Overflow
Some of my java programs need so many jar files to execute. For executing this, I may have to add all of those jar files in classpath variable of environment variables or else have to set classpath manually at command prompt each and every time when I open a new cmd prompt. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Muthu Saravanan
mshappylearning.wordpress.com › 2014 › 08 › 31 › java-path-and-classpath-settings-on-windows-command-prompt-system-variables
JAVA Path and Classpath Settings on Windows (command prompt / System Variables) | Muthu Saravanan
August 31, 2014 - setting Classpath set classpath=%classpath%;<java installed directory\lib\*.jar> eg: set classpath=%classpath%;C:\Program Files (x86)\Java\jdk1.7.0\lib\*.jar ... Since i installed JDK 7 on my system, that’s why it is showing java version as ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › different-ways-to-set-a-classpath-in-java
Different Ways to Set a Classpath in Java - GeeksforGeeks
July 23, 2025 - 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
🌐
Oracle
docs.oracle.com › javase › › 7 › docs › technotes › tools › windows › classpath.html
Setting the class path
For example, suppose you want the ... class path so that it contains C:\java\MyClasses. To run that app, you could use the following JVM command: C:> java -classpath C:\java\MyClasses utility.myapp.Cool...
Find elsewhere
🌐
Reddit
reddit.com › r/learnprogramming › java : how to use a -classpath in the command prompt.
r/learnprogramming on Reddit: Java : How to use a -classpath in the command prompt.
August 6, 2015 -

So I have two different .java files in two different directories. One contains the main method which calls the other one through its method name. . This is in the directory

E:\JavaWorld\TardyCoder\temp1

Here is my program which contains the main method with the fileName Lemons.java

public class Lemons{
public static void main(String args[]){

Sorra sorraObject = new Sorra();
sorraObject.testName();	
 }
 }

My another program is in the directory

E:\JavaWorld\TardyCoder\temp2

Here is my program Sorra.java which doesn't contain the main method.

 class Sorra{
public void testName(){
System.out.println("My name is Khan.");
 }
 }

I used -sourcepath to create two .class files like this:

   E:\JavaWorld\TardyCoder\temp1>javac -sourcepath E:\JavaWorld\TardyCoder\temp2 Lemons.java

Everything worked perfectly and i got two .class files in their respective directories.

Now I tried to use the -classpath to get the output like this:

E:\JavaWorld\TardyCoder\temp1>java -classpath .; E:\JavaWorld\TardyCoder\temp2 Lemons

But I'm getting an error :(

Error: Could not find or load main class E:\JavaWorld\TardyCoder\temp2

Please explain the right way to use -classpath in command prompt.

Edit: Got the answer. There should be no space after .;

Top answer
1 of 2
2
http://www.ibm.com/developerworks/library/j-classpath-windows/ Best article about the topic. Please include the error next time.
2 of 2
1
You need to put 2 line breaks to make paragraphs in your post. To format code blocks, indent with 4 spaces. Then your post becomes more readable and you'll get more help: So I have two different .java files in two different directories. One contains the main method which calls the other one through its method name. I used -sourcepath to create two .class files like this: E:\... javac -sourcepath E:\... FileName.java Now I tried to use the -classpath to get the output like this: E:\... java -classpath E:\.. FileName But I'm getting an error :( Please explain the way to use -classpath in command prompt. First things first, you should always mention errors when ever you ask for help. Anyway, I assume this isn't what you're actually executing, since it's not valid syntax. I assume that you must have removed paths and that the leading path is actually part of the prompt string (most people use $ to show the prompt string). If that's not the case, then this would be the underlying problem. It's noteworthy that you probably don't want to be using absolute paths here. You almost always want relative paths (eg, if you're in /foo/bar/baz and want to refer to a file with the path /foo/bar/tor/gat.png, you'd use the relative path ../tor/gat.png -- .. means go up a folder). Anyway, when you've compiled your Java files into class files, their location is the class path that you'd want. In 99% of projects, you don't need to set the class path because it defaults to including the current directory, which is what you'd want. Eg, if your project contains two files, A.java and B.java in the default package, you'd compile with javac A.java B.java # Or use `javac *.java` for simplicity which will result in the files A.class and B.class (and possibly others for inner classes, etc) appearing in the directory. You'd then merely have to point the JVM at the class with the entry point with java A Which requires no classpath since the class files are in the default package and the current working directory, and thus the JVM is able to find them. Now on the other hand, if your project had the files in foo/A.java and foo/B.java, where foo is the package they're in, you'd have to run the files from the base directory (not in the packages) with java foo.A # Note the dot instead of a slash And if foo.A needs foo.B, then the JVM will be searching for foo/B.class. So how does the JVM know where to look? That's what the classpath is for. In the cases above, we didn't have to set the class path because we made sure to work from the base directory from which all our packages are in. Usually you'd set the classpath for libraries, not for your own code. Having to set it for your own code may be indicative of you doing something wrong. If you get the general gist of what I'm saying here, perhaps you'll be able to figure out how to get things working (experiment a bit, if needed). If you're still stuck, elaborate on the exact paths you're using, the locations of files, the error message you're getting, and the packages that files are in.
🌐
Blogger
javarevisited.blogspot.com › 2011 › 01 › how-classpath-work-in-java.html
How to Set Classpath for Java on Windows and Linux? Steps and Example
$ set CLASSPATH=%CLASSPATH%;JAVA_HOME\lib; This way you can set the classpath in Windows XP, Windows 2000, or Windows 7 and 8, 10 as they all come with a command prompt.
🌐
HowToDoInJava
howtodoinjava.com › home › java basics › java classpath
How to set CLASSPATH in Java - HowToDoInJava
February 23, 2023 - Use -classpath argument to set classpath from command prompt/console.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › environment › paths.html
PATH and CLASSPATH (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
The preferred way to specify the class path is by using the -cp command line switch. This allows the CLASSPATH to be set individually for each application without affecting other applications.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › technotes › tools › windows › classpath.html
2 Setting the Class Path
April 21, 2026 - The class search path (class path) can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting the CLASSPATH environment variable. The -classpath option is preferred because you can set it individually for each application without affecting other ...
🌐
Drew University
users.drew.edu › bburd › JavaForDummies6 › classpath.pdf pdf
1 Chapter 2 Setting your Classpath
classpath for one invocation of the javac or java command. To do this, you type ... The set command holds for only one copy of the command prompt window.
🌐
@ankurm
ankurm.com › home › setting the classpath from the command line in java
Setting the Classpath from the Command Line in Java
October 28, 2025 - The classpath is the list of paths that Java checks for classes and resources. In this guide we’ll explore how to set the classpath in a few different ways—via the java and javac commands, through the CLASSPATH environment variable and by using the -cp / -classpath switch.
🌐
Edureka
edureka.co › blog › set-java-classpath
How To Set Classpath In Java | Java Path And Classpath | Edureka
June 19, 2023 - Moving on with this article on How to Set Java Classpath? Run Command Prompt 1. Type in the following echo %JAVA_HOME% This will echo the directory path of JAVA_HOME or it will echo nothing if Variable is not set.
🌐
TechVidvan
techvidvan.com › tutorials › how-to-set-path-in-java
How to set path in Java? - TechVidvan
March 21, 2024 - New System Variable: Set “Variable Name” and “Variable Value”. Set Variable Name as “path” and Variable Value as “your JDK path”. Restart Command Prompt: Close any open Command Prompt windows and open a new one. Your new classpath settings should now be active.
🌐
Java Tech ARC 3i
javatecharc.com › home › how to set java classpath?
Set Java Classpath - A Complete Guide - Java Tech ARC 3i
December 3, 2024 - CLASSPATH – The classpath is required during run time of class, JVM load classpath libraries and execute the java program. There are couple of way to set the java/jdk path, lets understand it. Before set the JDK Java class path if you execute any jdk command such javac, java it will get below. C:\>javac Hello.java 'javac' is not recognized as an internal or external command, operable program or batch file.
Top answer
1 of 3
1

There is no need for a batch file to specify the classpath for Java on command line as Jack wrote in his comment.

Take a look on the version 7 Java documentation pages:

  • Java
  • Setting the class path

There is -cp or better readable for humans -classpath which can be used on command line to define the classpath.

The paths to multiple classes can be specified by using a semi-colon as separator.

And double quotes around all paths must be used if one path contains a space character.

Example:

"%JAVA_HOME%\bin\java.exe" -classpath "C:\Java\My First Class;C:\Java\MySecondClass" MyJavaApp

This approach is mainly useful on using a shortcut (*.lnk) to a Java application which needs different classses than what is usually used and defined in system wide environment variable CLASSPATH.

But for developing and testing Java applications in a console window with a different list of classes than defined system wide, it is better to have a batch file for example with name JavaDevEnv.bat with following code

@echo off
title Java Development Environment
cd /D "Path to\Preferred Working Directory\For\Java\Development"
set "CLASSPATH=C:\Java\My First Class;C:\Java\MySecondClass"

and create a shortcut on Windows desktop or in Windows start menu with the command line

%SystemRoot%\System32\cmd.exe /K "Path to\Batch File\JavaDevEnv.bat"

defined in the properties of the shortcut file (*.lnk).

The working directory can be also defined with Start in in properties of the shortcut file instead of being set in batch file using change directory command.

And an appropriate Comment should be also written in properties of the shortcut file, for example same as used on command title which sets the title of the console window as hint for which purpose to use this shortcut.

A double click on this shortcut results in opening a new console window, executing the batch file which sets window title, working directory and environment variable CLASSPATH used by Java executed from within this console window and then remains open for user input.

2 of 3
0

Batch file: In order to run class file which uses classes of Some jar file and classes of same application.

As of Eclipse IDE Set all build path entries to the Class Path. As we are running it through batch file we need to set the target application class file too. As shown below.

REM MyApplication\mainClass.bat
REM MyApplication\target\classes - %~dp0target\classes;

mainClass.bat which contains set class path

@echo off
REM Maven local repository path
SET REPO=%USERPROFILE%\.m2\repository

REM Setting the class path
SET CLASSPATH=%REPO%\junit\junit\4.11\junit-4.11.jar;%REPO%\com\oracle\ojdbc5\11.1.0.7.0\ojdbc5-11.1.0.7.0.jar;%~dp0target\classes;%~dp0target\test-classes


java -Xmx256m com.github.yash777.MainClass

Java command line option to debug remotely

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000 <YourAppName>