jdk/bin/jpsshould list all the java process IDs running that system- subsequently invoke
jdk/bin/jinfo <pid>to see lot of information... what you require is also there...
jdk/bin/jpsshould list all the java process IDs running that system- subsequently invoke
jdk/bin/jinfo <pid>to see lot of information... what you require is also there...
No need to print the default classpath. In Java, the default classpath is just the current directory:
If -classpath and -cp are not used and CLASSPATH is not set, the user class path consists of the current directory (.).
(documentation of java:)
Note: For completeness' sake: Theree are two other paths where java will look for stuff:
- the bootstrap class path
- the extension directory
The bootstrap class path by default points to parts of the JDK, and you almost never want to mess with it (unless you want to override part of the JDK), so you probably should not worry about it. The extension directories are for extending the JDK; see http://docs.oracle.com/javase/7/docs/technotes/guides/extensions/index.html
debugging - How to debug classpath command line option (-cp) for java executable? - Stack Overflow
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
java - How to add directory to classpath in an application run profile in IntelliJ IDEA? - Stack Overflow
Java : How to use a -classpath in the command prompt.
Videos
In Intellij 13, it looks it's slightly different again. Here are the instructions for Intellij 13:
- 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
- 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)
- click on the dependencies tab
- Click the "+" button on the right and select "Jars or directories..."
- Find your path and click OK
- In the dialog with "Choose Categories of Selected File", choose
Classes(even if it's properties), press OK and OK again - You can now run your application and it will have the selected path in the class path
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:
- Go to the Project Structure, click on Modules, and click on your Module
- Choose the "Dependencies" tab
- Click the "+" button on the right-hand side and select "Jars or directories..."
- Add the directory(ies) you want (note you can multi-select) and click OK
- In the dialog that comes up, select "classes" and NOT "jar directory"
- 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.
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 .;