Hi guys,
I am new to Eclipse and would like to create a java project which I can run from the linux (kubuntu) bash terminal.
I've used Netbeans before and building it simply creates a jar file in the dist folder then I can run java -jar HelloWorld.jar and voila it runs.
This doesn't seem to be as straightforward with Eclipse however! (or am I missing something?) Not to dwell too much on why I am choosing to use eclipse over netbeans,
I would really like to (need to, for more memory-intensive project later) get a simple HelloWorld app to run from the linux terminal.
The steps I have followed so far are to create a HelloWorld app in eclipse as follows:
1. Create a new Java application and in Project Layout selected "Use project folder as root for resources and classes"
2. Create a package 'org'.
3. Create a class HelloWorld.java inside org with the following code:
package org;
public class HelloWorld {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
When I build and run the above project in Eclipse, it works fine.
But when running it in the bash terminal, I get the following error:
ltsmm@gertlx:~/eclipse/HelloWorld/org$ java HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld (wrong name: org/HelloWorld)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
I suspect it has something to do with package names and specified output directories during project
creation?
Having a .jar file to run in the end would be nice but not essential.
If anyone could provide a procedure / some advice for getting this relatively simple thing to work it would be much much appreciated!
Gert
eclipse/packages newbie