File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regarding ClassPath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding ClassPath " Watch "Regarding ClassPath " New topic
Author

Regarding ClassPath

Deepak Bobal
Ranch Hand

Joined: Feb 06, 2008
Posts: 96
I have a class at

C:\Documents and Settings\Administrator\Desktop\Richard\My

package My;
public class ABC
{
public void Add()
{
System.out.println("Hello World");
}
}

and another class PQR

at

C:\Documents and Settings\Administrator\Desktop

import My.*;
class PQR
{
public static void main(String[] arg)
{
ABC a=new ABC();
a.Add();
}

}

and at command Prompt i am at

C:\Documents and Settings\Administrator\Desktop>

and if i give

C:\Documents and Settings\Administrator\Desktop>javac -cp Richard PQR.java

it works fine

and generates class files

bur if i try to run

using

C:\Documents and Settings\Administrator\Desktop>java -cp Richard PQR

it gives ClassNotFoundException

How can it be ractified.

Thanks


Constant dripping hollows out a stone....
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Use this commend to run the program on windows

java -cp Richard;. PQR

and for linux or unix, use this command

java -cp Richard:. PQR


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
C:\Documents and Settings\Administrator\Desktop>java -cp Richard My.PQR

Add package name before classname.


SCJP 6
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Originally posted by punit singh:
C:\Documents and Settings\Administrator\Desktop>java -cp Richard My.PQR

Add package name before classname.


PQR class in not in My package...
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Ok, I read the question wrong.
Deepak Bobal
Ranch Hand

Joined: Feb 06, 2008
Posts: 96
Thanks a lot Ankit

java -cp Richard;. PQR

works

But why " ;. " is added at the end of classpath

what does it mean.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

It means that the JVM should look for class files in the Richard directory and then in the current directory. dot represents the current directory and semicolon is used to separate paths from each other in windows...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Regarding ClassPath
 
Similar Threads
J Creator Program
classpath
what's the difference between "override" and "hide"?
on the subject of packaging
Program is not compiles