jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Classpath Crisis Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Classpath Crisis" Watch "Classpath Crisis" New topic

Classpath Crisis

Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
Howdy folks,
I'm having a real problem involving classpath that I haven't been able to solve through either previous posts to this forum or through the sun documentation.
No matter what I do, my compiler seems to always use the current working directory for the classpath.
By way of example, I have the following file: C:\javafi~1\Test.java
When I enter the following command at the dos prompt, I get a file not found error.
c> javac Test.java
Which is what you would expect without explicitly including c:\javafi~1 in your class path setting. However, when I add C:\javafi~1 to my class path setting (in my autoexec.bat file; Windows 98)I still get the same error message.
Moreover, I still get a file not found error when I try:
C> javac Test.java -classpath C:\javafi~1
The only way I can compile the file is by first changing directories to the file in which Test.java is saved.
I'm at my wit's end and can't possibly imagine what's going wrong.....could any of you lovely people please suggest some solutions?

Fun programming etcetera!
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
Solution 1: javac C:\javafi~1\Test.java -classpath C:\javafi~1
Solution 2: javac Test.java -sourcepath C:\javafi~1
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
David, thanks for your thoughtful reply.
The first solution you propose worked just fine for me; though it doesn't seem any simpler (time wise, at least) than changing the current working directory.
I did have some problems with the second solution that you proposed. When I tried it I got the same file not found error. I'm wondering if, since this method works for you, there might be some other system attribute that is spoiling this solution for me? (I'm fairly new at system configuration)
Thanks again for your reply.
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
You're confusing path with classpath.

Path is for compiling. If you are not in the directory with the source file, you need to give the path to the source file (which is why solution #1 above works). (You also need to be sure that javac.exe is in your path, but it seems that that is not your current problem.)

Classpath is for running the program, so the JVM can find the *.class (compiled) it's trying to run. It has nothing to do with javac.

I think solution #2 should be more like:
javac -sourcepath C:\javafi~1 Test.java
since the options should come between the javac command and the name of the source file.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
I agree. Here's the link: http://aspose.com/file-tools
subject: Classpath Crisis
It's not a secret anymore!