1. jdk/bin/jps should list all the java process IDs running that system
  2. subsequently invoke jdk/bin/jinfo <pid> to see lot of information... what you require is also there...
Answer from K Adithyan on Stack Exchange
🌐
Mkyong
mkyong.com › home › java › how to print out the current project classpath
How to print out the current project classpath - Mkyong.com
August 30, 2012 - As per “Sham” comment, this works; System.out.println(System.getProperty(“java.class.path”).replace(‘:’,’\n’)); ... Thanks again, MKyong, very useful ! ... Thanks! Very helpful! ... Thank man. Love your blog. ... It’s “correct” in some sense, but I know of at least two cases where it’s not what you really want: (1) On systems where the classpath length may exceed command-line or other limits, the system property may include at least one level of indirection via the Class-Path keyword in a jar’s manifest.
Discussions

debugging - How to debug classpath command line option (-cp) for java executable? - Stack Overflow
I want to execute the java executable (Open JDK 11.0.2) on Windows from command line and I am not sure if I specify the class path option correctly, e.g. java -cp "./foo_\*/*" -version How can I ... More on stackoverflow.com
🌐 stackoverflow.com
java - Is there a way to get the classpath from a Intellij project in order to execute the project from the command line (terminal)? - Stack Overflow
I have created a large Maven project in Intellij IDEA that uses many libraries and Maven dependencies, I now have to be able to run it from the command line (using Terminal in MacOS Mojave). Is the... More on stackoverflow.com
🌐 stackoverflow.com
java - How to add directory to classpath in an application run profile in IntelliJ IDEA? - Stack Overflow
I'm trying to add a directory to the classpath of an application run profile If I override by using -cp x:target/classes in the VM settings, I get the following error: java.lang.NoClassDefFoundEr... More on stackoverflow.com
🌐 stackoverflow.com
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
🌐
Java2Blog
java2blog.com › home › core java › java path › print classpath in java
Print Classpath in Java - Java2Blog
February 14, 2022 - ... You can use System.getProperty("java.class.path") to get ClassPath in java. CLASSPATH variables tell application to location where it should find user classes. Default CLASSPATH is current working directory(.). You can override this value using CLASSPATH variables or -cp command...
🌐
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
To set Classpath for Java In Linux, ... your Linux or Unix Machine. Now to check the value of Java CLASSPATH in Linux type "echo ${CLASSPATH}" this will print the value of Classpath in the command prompt....
🌐
Blogger
javahungry.blogspot.com › 2022 › 09 › java-print-classpath.html
Java Print Classpath | Java Hungry
The java.class.path argument extracts CLASSPATH using System.getProperty() and split its paths using String's split() method as shown below in the example: import java.io.File; public class PrintClasspathJava { public static void main(String args[]) { String classpath = System.getProperty(...
🌐
Baeldung
baeldung.com › home › java › core java › understanding java’s classpath vs. build path
Understanding Java’s Classpath vs. Build Path | Baeldung
August 28, 2024 - To set the classpath via the command line, we use the -classpath option when running the java command: ... Here, MyProgram is the name of the main class, and /path/to/class/files is the directory where the class file is located.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › environment › paths.html
PATH and CLASSPATH (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
This will print the version of the java tool, if it can find it. 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.
Find elsewhere
🌐
HowToDoInJava
howtodoinjava.com › home › java examples › java – set classpath from command line
Java - Set Classpath from Command Line
January 25, 2022 - In Windows, the path separator is semicolon ( ; ) and the path separator in Linux is colon ( : ). ... Use -classpath or -cp option to provide the classpath locations while starting the Java application or tool.
🌐
How to do in Java
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.
🌐
Stack Overflow
stackoverflow.com › questions › 55859560 › is-there-a-way-to-get-the-classpath-from-a-intellij-project-in-order-to-execute
java - Is there a way to get the classpath from a Intellij project in order to execute the project from the command line (terminal)? - Stack Overflow
I have created a large Maven project in Intellij IDEA that uses many libraries and Maven dependencies, I now have to be able to run it from the command line (using Terminal in MacOS Mojave). Is the...
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Get Classpath from Classloader in Java - Java Code Geeks
December 9, 2024 - The method getURLs() returns an array of URLs that represent the locations where the ClassLoader is searching for classes. These URLs are then printed one by one using a for loop, displaying the classpath used by the custom ClassLoader to load classes. ... The ClassLoader is a crucial part of the Java runtime environment, enabling the dynamic loading of classes and resources.
Top answer
1 of 9
340

In Intellij 13, it looks it's slightly different again. Here are the instructions for Intellij 13:

  1. click on the Project view or unhide it by clicking on the "1: Project" button on the left border of the window or by pressing Alt + 1
  2. find your project or sub-module and click on it to highlight it, then press F4, or right click and choose "Open Module Settings" (on IntelliJ 14 it became F12)
  3. click on the dependencies tab
  4. Click the "+" button on the right and select "Jars or directories..."
  5. Find your path and click OK
  6. In the dialog with "Choose Categories of Selected File", choose Classes (even if it's properties), press OK and OK again
  7. You can now run your application and it will have the selected path in the class path
2 of 9
101

It appears that IntelliJ 11 has changed the method, and the checked answer no longer works for me. In case anyone else arrives here via a search engine, here's how I solved it in IntelliJ 11:

  1. Go to the Project Structure, click on Modules, and click on your Module
  2. Choose the "Dependencies" tab
  3. Click the "+" button on the right-hand side and select "Jars or directories..."
  4. Add the directory(ies) you want (note you can multi-select) and click OK
  5. In the dialog that comes up, select "classes" and NOT "jar directory"
  6. Make sure you're using that Module in your run target

Note that step 5 seems to be the key difference. If you select "jar directory" it will look exactly the same in the IDE but won't include the path at runtime. There appears to be no way to determine whether you've previously selected "classes" or "jar directory" after the fact.

🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 206757845-Intellij14-How-to-get-the-classpath-of-the-current-project-
Intellij14: How to get the classpath of the current project? – IDEs Support (IntelliJ Platform) | JetBrains
April 22, 2015 - Searching the forum, this question was already asked many years ago: https://devnet.jetbrains.com/message/502975#502975 Project project = (Project) event.getDataContext().getData(DataConstants.PROJECT); ProjectRootManager projectManager = ProjectRootManager.getInstance(project); projectManager.getFullClassPath(); However, it looks like it relies on API that does not exist anymore. By what was getFullClassPath() replaced in IntelliJ 14? Andrea ... "The classpath of the project" is not a very meaningful thing in IntelliJ IDEA because each module has its own independent classpath.
🌐
Medium
medium.com › javarevisited › back-to-the-basics-of-java-part-1-classpath-47cf3f834ff
Tutorial on how Java classpath works | Javarevisited
May 15, 2022 - However, it is required by the java command to run. Let’s compile this little project. First we create a bin folder to hold the compiled stuff in the root project folder then compile the two files [2]. > mkdir bin > javac src/java/myprogram/Main.java src/java/myprogram/utils/Util.java -d bin/ You should now have the following file structure. ClasspathProject/ | ---> src/java/myprogram/ | ---> Main.java | ---> utils/ | ---> Util.java | ---> bin/myprogram/ | ---> Main.class | ---> utils/ | ---> Util.class
🌐
Javaspring
javaspring.net › blog › java-print-classpath
Java Print Classpath: A Comprehensive Guide | JavaSpring.net
July 8, 2025 - User Classpath: This can be set for a specific Java application. It can be set using the -cp or -classpath option when running a Java program from the command - line. The simplest way to print the classpath in Java is by accessing the java.class.path system property.
🌐
Princeton CS
introcs.cs.princeton.edu › java › 15inout › classpath.html
Setting the Classpath in Java
If the CLASSPATH variable does not exist, select New. Type CLASSPATH for the variable name and .;C:\introcs for the variable value. Click OK three times. ... Use your favorite text editor (e.g., TextEdit) to add the following line to the file /Users/username/.bashrc.
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › java › different-ways-to-set-a-classpath-in-java
Different Ways to Set a Classpath in Java - GeeksforGeeks
July 23, 2025 - 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
🌐
Gradle
discuss.gradle.org › help/discuss
How can I print a parseable run time classpath? - Help/Discuss - Gradle Forums
March 10, 2021 - I managed to build a Java Gradle project, and I’m now trying to run it from the command line. For that, I’d need gradle to print the the runtime dependencies. If I do: gradle dependencies --configuration runtimeClasspath This prints out a decorated tree of dependencies, which is rather ...