Solved

classpath / cannot find class

Posted on 1998-12-19
16
1,224 Views
Last Modified: 2013-11-23
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
Comment
Question by:jdaues
  • 7
  • 5
  • 3
  • +1
16 Comments
 
LVL 4

Expert Comment

by:davidmwilliams
ID: 1229785
 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
 
LVL 4

Expert Comment

by:evijay
ID: 1229786
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
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229787
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
 
LVL 4

Expert Comment

by:davidmwilliams
ID: 1229788
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
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229789
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
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229790
jdaues:

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

Merry Christmas
0
 
LVL 4

Expert Comment

by:davidmwilliams
ID: 1229791
 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
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229792
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:jdaues
ID: 1229793
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
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229794
:)
so merry christmas again
0
 
LVL 4

Expert Comment

by:davidmwilliams
ID: 1229795
 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
 
LVL 4

Accepted Solution

by:
davidmwilliams earned 100 total points
ID: 1229796
 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
 

Author Comment

by:jdaues
ID: 1229797
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
 
LVL 4

Expert Comment

by:davidmwilliams
ID: 1229798
 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
 
LVL 4

Expert Comment

by:davidmwilliams
ID: 1229799
 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
 

Author Comment

by:jdaues
ID: 1229800
whew!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now