• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

classpath problem

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andrew Lit
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andrew Lit
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you all, now it is ok.
 
I think she's lovely. It's this tiny ad that called her crazy:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!