Hi Vinay
You can compile any class from anywhere, no matter in which directory
you are and no matter its package, but you can reference it (for
execution purposes or for compile another class using it) only by
properly taking into account its package.
For e.g., you can compile your file d:\vinay\check\Test.java file as:
1. cd /D D:\
javac vinay\check\Test.java
2. cd /D D:\vinay
javac check\Test.java
3. cd /D D:\vinay\check
javac Test.java
4. cd /D C:\temp
javac D:\vinay\check\Test.java
But the Test.class file generated "knows" the package to which it
belongs, based on the statement "package check;" statement in your file
(if any). However, when compiling, the javac command line doesn't care
about the package.
Now, when you compile Pac.java that depends on check.Test, the compiler
must find the class file based on the classpath. The compiler cares now
about the package and the position of Test.class or Test.java when
compiling Pack.java.
So, first of all, if Pack imports "check.Test", be sure that the
Test.java file contains the "package check;" statement at the beginning.
Then, be sure that the previously compiled Test.class or just Test.java
can be found based on the classpath and the package name. In other
words, D:\vinay (that contains check.Test) must be in the classpath when
compiling Pack.java in order to let the compiler to find check.Test.
For e.g.:
1. cd /D D:\
javac -cp \vinay vinay\check\pac\Pack.java
2. cd /D D:\vinay
javac check\pac\Pack.java -- or -- javac -cp . check\pac\Pack.java
3. cd /D D:\vinay\check
javac -cp .. pac\Pack.java
4. cd /D D:\vinay\check\pac
javac -cp ..\.. Pack.java
4. cd /D C:\temp
javac -cp C:\vinay D:\vinay\check\pac\Pack.java
Hope it helps
Mihai
vinay basavanal a écrit :
Hi all,
This may be a stupid question but i am facing this problem
I created a dir check under d:\vinay
so in d:\vinay\check
I wrote simple Test.java which just has a variable ;
and compiled it
Then i created a another dir pac
so in d:\vinay\check\pac
i wrote another pogramme Pac.java
package check.pac;
import check.Test;
public class Pac {
public static void main(String args[]) {
Test a = new Test();
}
}
then in d:\vinay\check\pac when i use javac d:\vinay\check\pac
Pac.java
i get cannot find symbol Test
or even when i use javac d:\vinay\check\ Pac.java
i get cannot find symbol Test
Regards
vins
--
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en