| 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
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
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
|
 |
 |
|
|
subject: doubt in -cp option....
|
|
|