PDA

View Full Version : CLASSPATH works for java.exe, not for javac.exe


Tweak'd
10-19-2006, 10:47 AM
Hello,

I've been using Java at school and now I'm trying to get it set up at home.
My .java and .class files are located in the same folder, called E:\School\Java\. I've set the CLASSPATH variable to that folder, in the Environment Variables in WinXP.

I have a HelloWorld.java and a HelloWorld.class file in the CLASSPATH folder.
Typing java HelloWorld in the command line executes the class file.

However, typing javac HelloWorld.java tells me that it cannot read HelloWorld.java. When I include the CLASSPATH in the javac call, like this javac %CLASSPATH%HelloWorld.java, it compiles the source file, like it should.

Some hours of Googling and experimenting lead me nowhere. I did learn that javac looks in the CLASSPATH folder for sourcefiles, unless the sourcepath option is set. That only made me more confused, since it only confirms that the problem shouldn't occur.

But I'm no expert and I must have done something wrong. I'd be very greatful if someone could help me out here.

Thanks.

Aradon
10-19-2006, 01:30 PM
I believe, and I may be wrong in this area, that javac does look at the classpath for files, however it's looking for .class files that it will use in the help of compiling the java file.

Which means you may have to explicitly call javac in the same place as the java file. From what I've experienced, the command java is pretty versatile in where you can call it, however the javac isn't.

That is most likely the problem, however if anyone else thinks otherwise *shrugs*

Tweak'd
10-19-2006, 02:01 PM
Thanks for the reply :)

At school, calling javac from the default directory in GNOME's terminal works fine, so I assumed I could make it work in a similar way at home.
But it's very likely that the default directory of GNOME's terminal is set to the directory in which the source files are.
So your answer makes perfect sense, thanks!

iota
10-19-2006, 05:48 PM
Your problem seem a little strange.
Once we've done Java Installler, it automatically sets EnvVar by default.

Tweak'd if you use WinXP, I suggest you use Powerful Java Editors like Borland or GEL (= freeware; download it from http://memescape.co.uk/gexperts/download.html ; it automatically searches your Java bin Dir. )

If you use Command Prompt a lot, this is just waste of time.
When you come to do projects, it'll make you sweat.

Tweak'd
10-19-2006, 08:51 PM
Thanks for the link, iota. I just gave Gel a quick try and it does the job for me!