H
Hongyu
Hi,
I am new to Java and Linux. I have a Linux PC and I tried to write a
simple HelloWorld java program and compile and run it, but I got
errors.
Below is the HelloWorld program:
package world;
public class HelloWorld
{
public static void main(String args[]) throws Exception
{
System.out.println("Hello World!");
}
}
after compiled it by "javac HelloWorld.java", it passed. And then I
tried to run it by the below command java HelloWorld and got errors.
So I searched on the internet and found that I need to specify the
package name, so I run by the below command:
java world.HelloWorld
But still got errors which was:
Exception in thread "main" java.lang.NoClassDefFoundError: world/
HelloWorld
I also tried to run by the command of "java -cp . HelloWorld", but I
got the same error.
I also tried to do "set CLASSPATH ".:~/workspace/temp", and then run
the program as above, but still get same error, where ~/workspace/temp
is the directory where my HelloWorld.java located.
When I did "which java", I got "/usr/bin/java"; and "which javac", I
got "usr/bin/javac". When I did "ls -l /usr/bin/java*", I got
something like below:
/usr/bin/java --> /etc/alternatives/java
/usr/bin/javac --> /etc/alternatives/javac
.......
When I did echo "CLASSPATH", I got a blank line.
When I did echo $SHELL, I got "/bin/bash"
Could someone kindly tell me how to solve the problem it?
Thanks a lot for the help in advance.
Hongyu
I am new to Java and Linux. I have a Linux PC and I tried to write a
simple HelloWorld java program and compile and run it, but I got
errors.
Below is the HelloWorld program:
package world;
public class HelloWorld
{
public static void main(String args[]) throws Exception
{
System.out.println("Hello World!");
}
}
after compiled it by "javac HelloWorld.java", it passed. And then I
tried to run it by the below command java HelloWorld and got errors.
So I searched on the internet and found that I need to specify the
package name, so I run by the below command:
java world.HelloWorld
But still got errors which was:
Exception in thread "main" java.lang.NoClassDefFoundError: world/
HelloWorld
I also tried to run by the command of "java -cp . HelloWorld", but I
got the same error.
I also tried to do "set CLASSPATH ".:~/workspace/temp", and then run
the program as above, but still get same error, where ~/workspace/temp
is the directory where my HelloWorld.java located.
When I did "which java", I got "/usr/bin/java"; and "which javac", I
got "usr/bin/javac". When I did "ls -l /usr/bin/java*", I got
something like below:
/usr/bin/java --> /etc/alternatives/java
/usr/bin/javac --> /etc/alternatives/javac
.......
When I did echo "CLASSPATH", I got a blank line.
When I did echo $SHELL, I got "/bin/bash"
Could someone kindly tell me how to solve the problem it?
Thanks a lot for the help in advance.
Hongyu