 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jack Black Guest
|
Posted: Wed Jan 10, 2007 8:55 pm Post subject: classpath and sourcepath |
|
|
I'm trying Java for the first time and haven't got very far. According to
the literature, you can set the path that the compiler (javac) uses to find
the source to be compiled. You just have to supply the path on
the -classpath (or -sourcepath) parameters of javac. Well I've tried this
many times in all sorts of combinations but it just doesn't work.
This is what I type (my source is in D:\JavaClasses)
javac -classpath D:\JavaClasses
Javac returns the message
javac: no source files
If I then try to compile my program with
javac MyProgram.java
it says
error: cannot read: MyProgram.java
I've also tried setting CLASSPATH as an environmental variable with no
better result.(set CLASSPATH=D:\JavaClasses)
Can someone please confirm that -classpath is the right option and that it
does in fact work the way I want it to?
I can get my program to compile by changing directory to D:\JavaClasses so
there's nothing wrong with my program or the compiler.
Jack |
|
| Back to top |
|
 |
Lew Guest
|
Posted: Sat Jan 13, 2007 8:10 am Post subject: Re: classpath and sourcepath |
|
|
Jack Black wrote:
| Quote: | I'm trying Java for the first time and haven't got very far. According to
the literature, you can set the path that the compiler (javac) uses to find
the source to be compiled. You just have to supply the path on
the -classpath (or -sourcepath) parameters of javac. Well I've tried this
many times in all sorts of combinations but it just doesn't work.
This is what I type (my source is in D:\JavaClasses)
javac -classpath D:\JavaClasses
Javac returns the message
javac: no source files
If I then try to compile my program with
javac MyProgram.java
it says
error: cannot read: MyProgram.java
|
Have you tried specifying the classpath and the source files at the same time?
Your first example shows a classpath but no source to compile, which could
explain the "no source files" error message.
The second one specifies the source but no sourcepath, which maybe made it
hard for the compiler to find the source. I assume here that you did not "cd"
to the D:/JavaClasses directory before invoking javac. If you did, then you
have a different problem. What was your working directory when you invoked
those commands?
Assuming your classes are in the default package (stop doing that!), you could
try
javac -sourcepath D:/JavaClasses MyProgram.java
This should locate your source even if you didn't "cd" first.
The compiler "classpath" option locates the root of .class hierarchies, not
source code. This is necessary when your compilation depends on classes
outside your source directory.
- Lew |
|
| Back to top |
|
 |
Jack Black Guest
|
Posted: Sun Jan 14, 2007 3:48 pm Post subject: Re: classpath and sourcepath |
|
|
Thanks for the reply Lew.
| Quote: | Have you tried specifying the classpath and the source files at the same
time?
|
Yes I have. I have tried exerything I can think of. But you have cleared up
for the difference between sourcepath and classpath. So thanks for that.
| Quote: | I assume here that you did not "cd" to the D:/JavaClasses directory before
invoking javac. If you did, then you have a different problem. What was
your working directory when you invoked those commands?
|
If I cd to D:\JavaClasses before invoking javac, it works fine. Anything
else fails.
| Quote: | Assuming your classes are in the default package (stop doing that!), you
could try
javac -sourcepath D:/JavaClasses MyProgram.java
Well that's what I would have thought as well. It doesn't though. It doesn't |
seem to find the source unless I'm in the same directory.
cheers
Jack
"Lew" <lew (AT) nowhere (DOT) com> a écrit dans le message de news:
FMWdnS8tJoSkxzXYnZ2dnUVZ_vupnZ2d (AT) comcast (DOT) com...
| Quote: | Jack Black wrote:
I'm trying Java for the first time and haven't got very far. According to
the literature, you can set the path that the compiler (javac) uses to
find the source to be compiled. You just have to supply the path on
the -classpath (or -sourcepath) parameters of javac. Well I've tried this
many times in all sorts of combinations but it just doesn't work.
This is what I type (my source is in D:\JavaClasses)
javac -classpath D:\JavaClasses
Javac returns the message
javac: no source files
If I then try to compile my program with
javac MyProgram.java
it says
error: cannot read: MyProgram.java
Have you tried specifying the classpath and the source files at the same
time? Your first example shows a classpath but no source to compile, which
could explain the "no source files" error message.
The second one specifies the source but no sourcepath, which maybe made it
hard for the compiler to find the source. I assume here that you did not
"cd" to the D:/JavaClasses directory before invoking javac. If you did,
then you have a different problem. What was your working directory when
you invoked those commands?
Assuming your classes are in the default package (stop doing that!), you
could try
javac -sourcepath D:/JavaClasses MyProgram.java
This should locate your source even if you didn't "cd" first.
The compiler "classpath" option locates the root of .class hierarchies,
not source code. This is necessary when your compilation depends on
classes outside your source directory.
- Lew |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|