running java programs on linux

Java Note

=========

did a simple hello world program (my first in java), compiled it and then tried to run it but this happens (note bin is /java/bin);

[root@localhost bin]# ./java [PATH TO PROGRAM]/hello

Exception in thread "main" java.lang.NoClassDefFoundError: [PATH TO PROGRAM]/hello

is this because i haven't linked java to it's standard classes or I haven't set classpath or what.

please give answer in plain english as i'm new to both java and linux (i'm using fedora core 1).

[538 byte] By [johnmmcparland] at [2007-9-30 16:15:18]
# 1

OK, assuming you have paths set up correctly, and you do not have an environment variable CLASSPATH, do the following

1. cd into the directory where your java file is

2. Type the following (assuming your program is Hello.java) javac Hello.java

3. Assuming this compiled, you should now have a file called Hello.class

4. To run it, type the following java Hello

If that does not work, make sure you have a main method which looks something likepublic static void main (String [] args) {

System.out.println("Hello World");

}

Get back if you have more problems.

EvilEdna at 2007-7-5 23:47:40 > top of Java-index,Administration Tools,Sun Connection...
# 2
From this:[root@localhost bin]#I think you use "root" user. It is generally not a good idea to run things as root which do not have to. I suggest to create a non-root user and to play around with it.
BIJ001 at 2007-7-5 23:47:40 > top of Java-index,Administration Tools,Sun Connection...
# 3
Try like this. It should work. [root@localhost bin]# ./java -classpath [PATH TO PROGRAM][PATH TO PROGRAM]/hello- Ramesh
Ramesh_Gojji at 2007-7-5 23:47:40 > top of Java-index,Administration Tools,Sun Connection...