Reputation: 1330
I am sure this is a very newbie question, but writing Java app after years. I have written a simple java code to print "HelloWorld"
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(" inside MAIN !!!");
}
Now I have created my project in eclipse & the structure is "/home/workspace/HelloWorld/src/com/android/test/helloworld/HelloWorld.java" & eclipse creates the .class at "/home/workspace/HelloWorld/bin/com/android/test/helloworld/HelloWorld.class". This runs successfully in Eclipse console. Now I want to run it though my Ubuntu 11.04 terminal.
If i cd
upto the .class parent folder & use java .HelloWorld
, it throws an ClassNotFoundException
Exception in thread "main" java.lang.NoClassDefFoundError: /HelloWorld
Caused by: java.lang.ClassNotFoundException: .HelloWorld
If I write the same prog with the source file & class file generated in the same default package, I am able to run it through the terminal.
Upvotes: 1
Views: 1968
Reputation: 5564
Also note the answer here: Runnable jar file generated by Eclipse wont execute?
Basically if you had Eclipse export your project as a "runnable jar" you can run it with:
java -jar YOURJAR.jar
Upvotes: 0
Reputation: 1074
cd /home/workspace/HelloWorld/bin/
and run
java com.android.test.helloworld.HelloWorld
You must always use the classes with their full qualified name (package + class name)
Upvotes: 3