views:

108

answers:

3

I have these files:

c:\MY_SOURCES\AClient.java
c:\MY_SOURCES\Pluto.java
c:\MY_SOURCES\com\Classes\Pluto.class

Into AClient.java I have

import com.Classes.*;
Pluto p = new Pluto();

When I compile the file with:

javac -classpath . AClient.java

the compiler tell me that it cannot access Pluto as bad source file Pluto.java ... but if I move Pluto.java away from c:\MY_SOURCES it compiles.

+1  A: 

Just reiterating...

C:\MY_SOURCES\AClient.java
C:\MY_SOURCES\com\Classes\Pluto.java

Assuming AClient.java contains...

import com.Classes.*;

public class AClient {
   Pluto p = new Pluto();
}

This compilation does works

C:\MY_SOURCES\javac *.java
prem
not correct:C:\MY_SOURCES\com\Classes\Pluto.class not Pluto.java that is into C:\MY_SOURCES
xdevel2000
post the content of Pluto.java or exact error... or see if you move the Pluto.java to com/Classes folder. If both Pluto.java and Pluto.class are similar.
prem
A: 

Maybe you introduced an error in your Pluto file. When you try to compile AClient it will also try to compile Pluto (since it's used by AClient) and will hit the error. If you remove Pluto.java you have the class file there from a previous (successful) compilation, and it uses that, and it works. You should check Pluto.java and see if it compiles by itself, or if there are any other problems with it.

Andrei Fierbinteanu
+2  A: 

Your source folder should mirror your package structure. If it does not javac gets confused. Ideally your compiled .class folder should be in a different root to your source folder.

So

c:\MY_SOURCES\AClient.java (assuming in the default package)
c:\MY_SOURCES\com\Classes\Pluto.java

c:\MY_COMPILED\com\Classes\Pluto.class

javac -classpath=c:\MY_COMPILED -d 
c:\MY_COMPILED\ c:\MY_SOURCES\AClient.java
mlk