aspose file tools*
The moose likes Beginning Java and the fly likes classpath problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "classpath problem" Watch "classpath problem" New topic
Author

classpath problem

Andrew Lit
Ranch Hand

Joined: Jul 01, 2002
Posts: 135
Hi,
i've searched the forum but couldn't find the solution.
my autoexec.bat contains this:

i try to compile and execute questiontest.java; the i've mentioned contained in the c:\java\question\; when i type

compiler gives me an error cannot read file.
but when i type

everything compiles without errors.
after typing
i get NoClassDefFoundError.
What is my problem? What should i change?
Thank you in advance.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Did you "cd" (change directory) to the c:\java\question\ directory before you javac and/or java?

Path contains the path to javac. Otherwise you would get a message similar to: "Bad command or filename". However you still need to tell it where the file is that you want it to use if you're not in the same subdirectory as the file.

After you compile, do you see a file named questiontest.class in the c:\java\question\ directory? I think you would not if you were not in that subdir when you did the "javac" thing.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Andrew Lit
Ranch Hand

Joined: Jul 01, 2002
Posts: 135
Originally posted by Marilyn de Queiroz:
Did you "cd" (change directory) to the c:\java\question\ directory before you javac and/or java?
Path contains the path to javac. Otherwise you would get a message similar to: "Bad command or filename". However you still need to tell it where the file is that you want it to use if you're not in the same subdirectory as the file.

Yes i have to cd. And all you said is true. But i can't understand what is wrong with my settings.

C:\j2sdk1.4.1_02\BIN; - is the path of java and javac;
C:\JAVA;C:\JAVA\QUESTION; - is the path where my *.java files are.
;C:\j2sdk1.4.1_02\LIB;C:\JAVA;C:\JAVA\QUESTION; - is the path where *.class file are contained.
c:\> javac QuestionTest.java
error : Cannot read: QuestionTest.java
Could you tell what is wrong here?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Nothing is wrong with your settings.
javac just can't find the file.
Whenever you open a file in any application, you have to tell the app where the file is.

In the command

c:\> javac QuestionTest.java

javac assumes that the QuestionTest.java file is in the current directory (i.e. c:\) unless you tell it otherwise.

You can either use

c:\>javac c:\java\question\QuestionTest.java

or

c:\java\question\>javac QuestionTest.java

javac c:\java\question\questiontest.java
won't work because of the case sensitivity ('q' rather than 'Q' and 't' rather than 'T').

If you have a file in c:\documents\text.txt and you want to open it with notepad, for example, can you just type

c:\>notepad text.txt

??

I think not. You will have to type

c:\>notepad c:\documents\text.txt
or
c:\documents\>notepad text.txt

because notepad doesn't know where the text.txt file is.
[ April 26, 2003: Message edited by: Marilyn de Queiroz ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I'd recommend adding a .; to the front of your classpath setting. You've a lone semicolon for some reason. The . (DOT) would tell the system to first consider the current directory.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Andrew Lit
Ranch Hand

Joined: Jul 01, 2002
Posts: 135
thank you all, now it is ok.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classpath problem