This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in -cp option...." Watch "doubt in -cp option...." New topic
Author

doubt in -cp option....

Ganeshkumar cheekati
Ranch Hand

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


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

CODE:2


I have compiled the above code with command
D:\java\scjp\c-1>javac �cp C:\ n �d . Cp2.java
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���.


CODE:3



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

Then it is showing compilation error as:

Can not access Cp1
Bad class file:C:\Cp1.java
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
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

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

javac Cp3.java

then all three files will get compiled...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
Don't get me started about those stupid light bulbs.
 
subject: doubt in -cp option....