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.
🌐
Princeton CS
introcs.cs.princeton.edu › java › 15inout › classpath.html
Setting the Classpath in Java
Go to that directory and compile them. ... From DrJava, choose the menu option Edit -> Preferences -> Resource Locations -> Extra Classpath -> Add and select C:\introcs. Click the Apply button, then the OK button. To set the classpath for the Windows XP Command Prompt:
Discussions

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
java - Setting Classpath using command prompt in Windows 7 - Stack Overflow
set classpath= %classpath%;C:\java-programes\Servlet-Programing-new1\TotalUsersOnline\lib\servlet-api\*.jar;C:\java-programes\Servlet-Programing-new1\TotalUsersOnline\lib\servlet\*.jar; More on stackoverflow.com
🌐 stackoverflow.com
September 14, 2013
jar - classpath - running a java program from the command line - Stack Overflow
You have to provide the classpath with all your dependencies when you run your application as well. ... I ran it by running java Generator . Generator is a class that calls a method in AvroReader.java ... Importing has nothing to do with loading classes or setting CLASSPATH. More on stackoverflow.com
🌐 stackoverflow.com
Setting JAVA_HOME path
It means that you have not configured the JAVA_HOME environment variable. Using a virtual terminal application, type in: update-alternatives --config java, which will give you the location of JDK listed under Path column. Depending on the installed version of JDK, it will be something like: /usr/lib/jvm/java-14-openjdk-amd64/bin/java If you have installed multiple versions of JDK, all of them will be listed here 2. Using text editor such as nano and terminal emulator, type in: nano /etc/profile.d/jdk_home.sh This will create and open for editing a new script file named jdk_home.sh under the location /etc/profile.d, where you need to type in: export JAVA_HOME= where JDK-Location should not include the /bin/java directories. For example: EXPORT JAVA_HOME=”/usr/lib/jvm/java-14-openjdk-amd64” This will set your environment variable JAVA_HOME The steps above are if you have installed JDK using apt package manager tool, you also have the option of using SDKMAN which will configure all environment variables for you automatically. More on reddit.com
🌐 r/vscode
12
1
February 27, 2020
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › environment › paths.html
PATH and CLASSPATH (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
If the version is old or you get the error java: Command not found, then the path is not properly set. To set the path permanently, set the path in your startup file. For C shell (csh), edit the startup file (~/.cshrc): ... For ksh, the startup file is named by the environment variable, ENV. To set the path: ... The CLASSPATH variable is one way to tell applications, including the JDK tools, where to look for user classes.
🌐
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
🌐
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 - 4) The Permanent Solution is set these path settings in System variables · 1) Right click on Computer–>Properties–>Advance System Settings–>Advanced–>Environment Variables · 2) setting Path In the System Variables you will find Path ...
🌐
Oracle
docs.oracle.com › javase › › 7 › docs › technotes › tools › windows › classpath.html
Setting the class path
The class search path (more commonly known by the shorter name, "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 ...
Find elsewhere
🌐
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
Classpath can be specified using CLASSPATH environment variable which is case insensitive, -cp or -classpath command-line option or Class-Path attribute in manifest.mf file inside the JAR file in Java.
🌐
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.
🌐
@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 - java -cp ".:/home/user/lib/commons-io-2.8.0.jar" MyProgram · When you set CLASSPATH, Java uses that value for every subsequent invocation unless overridden by -cp.
🌐
Michigan State University
web.pa.msu.edu › reference › jdk-1.2.2-docs › tooldocs › solaris › classpath-linux.html
Setting the class path
The 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 applications and ...
🌐
Edureka
edureka.co › blog › set-java-classpath
How To Set Classpath In Java | Java Path And Classpath | Edureka
June 19, 2023 - If you want to specify classpath while running any program using command line you can use Java -cp “some.jar;someOther.jar” com.edureka.HelloWorld . Here these two jars will be available to the program currently executed.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › technotes › tools › unix › classpath.html
2 Setting the Class Path
April 21, 2026 - You can change the class path by using the -classpath or -cp option of some Java commands when you call the JVM or other JDK tools or by using the CLASSPATH environment variable. See JDK Commands Class Path Options. Using the -classpath option is preferred over setting the CLASSPATH environment ...
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
How to set Classpath in Java - Java Code Geeks
May 10, 2021 - According, to the Oracle docs · The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value. ... Open the command prompt. Run ...
🌐
How to do in Java
howtodoinjava.com › home › java basics › java classpath
How to set CLASSPATH in Java - HowToDoInJava
February 23, 2023 - Learn how to set classpath in Java either as an environment variable and pass as the command-line argument.
🌐
Coderanch
coderanch.com › t › 370926 › java › Setting-CLasspath-command-line
Setting CLasspath from command line (Java in General forum at Coderanch)
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums · this forum made possible by our volunteer staff, including ... ... Hi, I am trying to set a classpath through command line as follows-- java -classpath -Dcl.prop=C:\\server.properties but the command line argument needs a "classname".....however I am doing this to be able to read the value of cl.props in the jsp using a System.getProperty("cl.prop"); How do I do this?