• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1273
  • Last Modified:

classpath / cannot find class

i am having problems with the classpath when trying to run a java program. normally, i do it from VisualCafe, so i don't know much about compiling and running for the command line for Java programs, but i ultimately want to run this program from another program, so i am trying to build the command to do so.

if i am in the folder in which my source code resides, from the MS DOS prompt (running windows NT) i can compile and run the Java program with no trouble:
D:\Java\applications\foo\>javac foo.java
D:\Java\applications\foo\>java foo

if i try to overtly specify (i guess _override_), the classpath, specifying where the JDK code is, and where my source code is (because that is what i will need to do when i run foo from another program), like:

java -verbose -classpath C:\VisualCafeWDE\Java\src\java;D:\Java\applications\foo\ foo

it blows up, saying :

[Loaded c:\VisualCafeWDE\Java\Src\java\lang\Thread.class]
Unable to initialize thread: cannot find class java/lang/Thread

curiously, if i type:
D:\Java\applications\foo\>set CLASSPATH
to see what the classpath is, the path that it returns (that is set in autoexec.bat) does not contain the location of the
JDK code.  this may not be so odd.  i'm not sure of the role of the autoexec.bat in Windows NT from an MS Dos prompt.  it may be completely ignored. It may be using the classpath set in Visual Cafe.  I am using the Visual Cafe JIT compiler from the DOS prompt.

can someone tell what is going on?
and how to get what i need?
0
jdaues
Asked:
jdaues
  • 7
  • 5
  • 3
  • +1
1 Solution
 
davidmwilliamsCommented:
 Check your System control panel and look to see if the CLASSPATH is set there, under the Environment tb page.
  Also, when you set your CLASSPATH you can't point it to the Java API src files, you need to point it to the actual class files themselves.  These are probably in a file, classes.zip, and probably in a directory like C:\VisualCafeWDE\Java\lib - so, you would actually want to use C:\VisualCafeWDE\Java\lib\classes.zip in your CLASSPATH - or directly on the java command line.
0
 
evijayCommented:
So, as williams pointed out, you can use the following command

java -verbose -classpath C:\VisualCafeWDE\Java\lib\classes.zip;D:\Java\applications\foo foo

regards

0
 
heyhey_Commented:
normally if you don't use the -classpath switch java.exe look for its classes.zip file in the appropriate (lib) directory (Java 1.1) - you don't have to include the classes.zip file into your CLASSPATH variable.

but if you use the -classpath command line switch you MUST include the classes.zip file yourself.
(i think that this situation is descrobed in the docs.)
so if you don't need some Sumantec classes you can use this

java -verbose -classpath C:\jdk1.1.7b\lib\classes.zip;D:\Java\applications\foo\ foo
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
davidmwilliamsCommented:
I don't see that HeyHey should get his answer marked correct when he simply repeated my comments - and hasn't even bothered to use the same directories in his example as you did in your question.
0
 
heyhey_Commented:
davidmwilliams:
The real problem is that if you use the command line switch -classpath you have to INCLUDE the classes.zip file as one of the parameters.
If you don't use the -classapth switch, you can NOT INCLUDE the classes.zip file from the CLASSPATH variable

so this
java -classpath C:\VisualCafeWDE\Java\lib\classes.zip;D:\Java\applications\foo foo

works the same way as this (at least for JDK 1.1)
SET CLASSPATH =D:\Java\applications\foo
java foo

in your answer you are exaplaining "how to set the CLASSPATH variable", which was not the main question (i think)

and of course if jdaues is not satisfied from my answer he can easy reject it and Grade you.

best regards
  heyhey
0
 
heyhey_Commented:
jdaues:

if you think that davidmwilliams's comment solves your problem, please reject my answer

Merry Christmas
0
 
davidmwilliamsCommented:
 Of course you can include classes.zip in your CLASSPATH, whether or not you set an environment variable, or use the -classpath directive on the command line.  However, javac should be able to figure it out based on its installed location.  To say you CAN NOT include it is plain wrong and untrue.
  The questioner was wanting to know if he had a current classpath and how to determine its value, and also, what was wrong with the -classpath he was passing.  The problem was that he was using the src directory, when he should have had the path to the classes.zip file.
  I just don't see that you added anything in any way.
0
 
heyhey_Commented:
davidmwilliams:
the REAL problem is that you SHOULD include the classes.zip file if you use the -classpath switch (NO MATTER if you have already SET the CLASSPATH variable or NOT)
 javac should be able to figure out classes.zip if you don't use -classapth switch
 javac is NOT able to figure out classes.zip if you use -classapth switch

so this won't work
[c:\]java -classpath . test
Unable to initialize threads: cannot find class java/lang/Thread

and this will work
[c:\]java -classpath d:\java\jdk1.1.7A\lib\classes.zip;. test

i just make a short explanation - the real answer was given by evijay
>> java -verbose -classpath C:\VisualCafeWDE\Java\lib\classes.zip;D:\Java\applications\foo foo

and again - i don't NEED these points, I will be GLAD if you receive them (although evijay has posted better comment) as a Christmas Present

Merry Christmas and Happy New Year

P.S.
>> If you don't use the -classapth switch, you can NOT INCLUDE the classes.zip file from the CLASSPATH variable
that is
. you can EXCLUDE the classes.zip ... (as you know - javac should be able to figure it out ;). sorry for my English


0
 
jdauesAuthor Commented:
gentlemen or ladies (as the case may be)

i do not enjoy playing the role of Santa Claus with the points,
but decisions must be made.

the essence of my problem is that i was using the Java source files
in my classpath, not the Java class files, as davidmwilliams pointed out.
he also suggested looking at the classpath setting in System | Environment,
which was educational in that it had the classes.zip directory in it.


0
 
heyhey_Commented:
:)
so merry christmas again
0
 
davidmwilliamsCommented:
 HeyHey, I think you've missed something here.  You seem to be trying to argue with me about exactly what I have already said.
  In my original comment I already pointed out that the classes.zip file needed to be added to jdaues' -classpath directive.  I'm not sure where your problem is -- what you are saying is what I have ALREADY said ... why are you trying to insist it to me, when it is not in dispute?
  As to your comment about 'not including' classes.zip in the CLASSPATH variable, I see what you are saying now.  When you say 'you CAN NOT include it' it sounds like you are saying that you are not able to; it is not possible.  I see from your latest comment now that what you are really saying is that you do not need to include it, you can choose not to include it.  This is correct, and so again, we are agreed.
  Evijay's comment was a simple agreement with what I said, as he clearly indicates.
0
 
davidmwilliamsCommented:
 Thanks, Jdaues, for the arbitration.  I'm pleased you've been able to resolve your problems.
  HeyHey, I'm glad we've resolved our miscommunications ...
0
 
jdauesAuthor Commented:
one more question to davidmwilliams:

the classpath setting in my System | Environment has perhaps redundant info:

C:\VisualCafeWDE\JAVA\LIB\CLASSES.ZIP; C:\VisualCafeWDE\JAVA\LIB;

if classes.zip were the only file in the folder, i would think this is redundant info.
however, i also have symclass.zip (which i don't actually use, i never anything
but standard JDK).  but assuming i did, would simply specifying the folder
suffice for finding any .zip file containing classes, or must the actual name of the
zip file be specified.

furthermore, how does Java know that the classes are contained in the zip files?
(its just 'built in' i guess)


0
 
davidmwilliamsCommented:
 The actual zip file must be referenced, if you want to use something from within symclass.zip.
  Java looks for class files in two ways -- either as files in a directory hierarchy under directories in the CLASSPATH, or inside zip (and jar) files explictly stated in the CLASSPATH.
  It does not actually know 'in advance' the class files in any given zip file - or indeed, even if a class it wants is in a zip file.  Java must search for the files it wants in each file and directory in the CLASSPATH (until it makes a match, or runs out of things to search).
  You could rename the classes.zip if you like, and so long as the new name was in your CLASSPATH, all should work fine.  Also, you could even unzip the classes.zip file and point your CLASSPATH to the directory where you did this, and all would work fine, again.  However, it is helpful to zip everything up for ease of deployment, over the Web.
  Hopefully this makes sense ...
0
 
davidmwilliamsCommented:
 The actual zip file must be referenced, if you want to use something from within symclass.zip.
  Java looks for class files in two ways -- either as files in a directory hierarchy under directories in the CLASSPATH, or inside zip (and jar) files explictly stated in the CLASSPATH.
  It does not actually know 'in advance' the class files in any given zip file - or indeed, even if a class it wants is in a zip file.  Java must search for the files it wants in each file and directory in the CLASSPATH (until it makes a match, or runs out of things to search).
  You could rename the classes.zip if you like, and so long as the new name was in your CLASSPATH, all should work fine.  Also, you could even unzip the classes.zip file and point your CLASSPATH to the directory where you did this, and all would work fine, again.  However, it is helpful to zip everything up for ease of deployment, over the Web.
  Hopefully this makes sense ...
0
 
jdauesAuthor Commented:
whew!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now