Yes, the poster, Kenny Freeman, is correct. To run a class HelloWorld, which
contains a static method 'main()', you need to type:
java HelloWorld
As long as the directory '.' is in your classpath, and the file
HelloWorld.class is in this directory, and HelloWorld is not a part of a
package, this will work. If HelloWorld is in a package (say, package
'com.fubar'), then you need to type:
java com.fubar.HelloWorld
Think of your classpath as a sort of LD_LIBRARY_PATH, with packages being
contained in subdirectories under directories contained within your CLASSPATH
(replacing the '.' with a '/', of course).
BTW, if you ever decide to package your '.class' files into a jar file, the
jar file needs to be explicitly included in your class path. Let's assume you
package the HelloWorld.class into a jar file called 'fubar.jar', by using the
command:
jar cvf fubar.jar HelloWorld.class
Then, to run HelloWorld, you need to have fubar.jar in your classpath:
export CLASSPATH=${CLASSPATH}:./fubar.jar
Finally, you can now run the program (again, assuming that HelloWorld is not
part of a package) using:
java HelloWorld
I hope this helps!
-dan
[EMAIL PROTECTED]
Aaron Brick wrote:
> my JDK installation seems to be weird. i saw a previous post relevant to
> this problem in the archive but the responses i saw weren't helpful.
>
> when i do "java HelloWorld.class" it complains about not being able to
> find the class file - even if i pass the full path - until i do a
> "-classpath `pwd`", or its equivalent. is this normal behavior?
>
> then - this is the step i have not been able to solve - it complains about
> not being able to find a class file called "java/lang/Thread". well, i
> have tried a large number of things with the Thread.class file, including
> renaming it and putting its path in classpath, putting it in ad-hoc
> subdirs in the java/classes dir (where i'm trying all this), etc. i just
> can't get it to find the file.
>
> i mailed one member of this list and he told me to download some different
> classes.zip file - however, it didn't appear to be on the russian server
> he gave me. why the discrepancy, and what is the deal with this problem,
> anyone?
>
> i have:
>
> JDK 1.1.6v2, glibc, i386 on Debian 2.0 (2.0.34), libc6. i don't have my
> machine handy so i'm sorry i don't have the loader or X versions but i can
> certainly supply them later.
>
> i would say this problem is of fairly high severity because it prevents me
> from running any program at all! it may be that it is an isolated incident
> but i sure thought the install went fine and my system is not weirdly
> hacked or anything.
>
> thanks for your responses.
>
> aaron brick.
>