File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in -cp option.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in -cp option...." Watch "doubt in -cp option...." New topic

doubt in -cp option....

Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
My working directory structure is :\java\scjp\c-1

I have compiled the above code by using command
D:\java\scjp\c-1>Javac -d C:\
Cp1.class file is created under package pack1 in C:\


I have compiled the above code with command
D:\java\scjp\c-1>javac �cp C:\ n �d .
I got Cp2.class file under package pack2 in my current working directory�..

I run Cp2 with command
D:\java\scjp\c-1>java �cp C:\;. pack2/Cp2
I got output as �yeah I got it���.


I am compiling this code with command:
D:\java\scjp\c-1>javac -cp C:\;.

Then it is showing compilation error as:

Can not access Cp1
Bad class file:C:\
File does not contain class Cp1
Please remove or make sure it appears in the correct subdirectory of the classpath.
Cp1 c1=new Cp1();
1 error

Is there any mistake in command?
How can I compile the above code?

SCJP5 and SCWCD1.5
Think Twice Act Wise...
Ankit Garg

Joined: Aug 03, 2008
Posts: 9462

Ganesh you should keep the source files in the folders of their corresponding packages. It is not compulsory but if don't do that, and while compiling a file, if it finds a .java file in the wrong directory i.e. not in it's package directory, then it starts showing error. I don't know the exact mechanism, but you problem will be solved if you make this hierarchy

Now if you have not set the classpath, and if it is set and it includes a dot (.) in it, then just move to the directory folder and then use the command


then all three files will get compiled...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: doubt in -cp option....
It's not a secret anymore!