Created a simple class named "Main" in the package "javaencryptor" using the
NetBeans IDE 4.1. I am able to step through it until the end. Now, when I
try to run the same one from the command line it craps out! here are the
steps I follow:
1. Opened a DOS window on the directory where the Main.class file is (the
class is also named Main)
2. Checked that "java -version" shows the 1.5 version
3. typed "java -client Main" (but also tried "java -client Main.java" and
"java Main.class" and "java Main" but I get
Exception in thread "main" java.lang.NoClassDefFoundError: Main (wrong name:
javaencryptor/Main)
at java.lang.ClassLoader.defineClass1(Native Method)
:
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
What am I doing wrong?
java -classpath .. javaencryptor.Main
'-classpath ..' tells Java your class can be found from the
parent directory of the *package* from which you are running
the class.
'javaencryptor.Main' tells Java to look for the class named
'Main' in the package 'javaencryptor'.
To run it from the *parent* directroy, you might type
java -classpath . javaencryptor.Main
..or..
java -cp . javaencryptor.Main
..or..
java javaencryptor.Main
BTW - Java's 'main(String[] args)' method makes 'Main'
a poor name for a class!
HTH
> Created a simple class named "Main" in the package "javaencryptor"
So the fully qualified class name is "javaencryptor.Main".
> 1. Opened a DOS window on the directory where the Main.class file is (the
> class is also named Main)
That is not be the root of where the class is.
> What am I doing wrong?
You aren't using the real class name.
>Created a simple class named "Main" in the package "javaencryptor" using the
>NetBeans IDE 4.1. I am able to step through it until the end. Now, when I
>try to run the same one from the command line it craps out! here are the
>steps I follow:
Then something works in the IDE but not the command like this hints
the classpath is the problem. See
http://mindprod.com/jgloss/classpath.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
> BTW - Java's 'main(String[] args)' method makes 'Main'
> a poor name for a class!
Can you please explain why? Class Main is found in many packages (ant,
log4j, javac).
>
>Can you please explain why? Class Main is found in many packages (ant,
>log4j, javac).
Because this is a newbie group and people are forever confusing
methods and classes and getting the naming conventions wrong.
Not only do you confuse newbies, we can't tell if you REALLY knew what
you were doing.
Further, the name Main suggests the starting class of a great set of
classes. It tells you nothing about what it does if it is the only
class.
As for the poor name of the class, granted, it is a poor name but it is the
one NetBeans generated and since I was just trying some things out I did not
bother to change it.
Thanks!
Emilio
http://www.FocusOnPanama.com/
"Andrew Thompson" <seemy...@www.invalid> wrote in message
news:17D%e.4465$U51....@news-server.bigpond.net.au...
> As for the poor name of the class, granted, it is a poor name but it is the
> one NetBeans generated ..
'Poor name', leading on to ..
>..and since I was just trying some things out I did not
> bother to change it.
..'poor excuse'. ;-)
> Thanks!
No worries. :-)
Understood. All three points. Thanks for the explanation.