I built a package called “com.hello” in eclipse and I wrote an easy HelloWorld program. Eclipse automatically added “package com.hello;” on top of my program. And HelloWorld.java was put in
F:\workspace\helloWorld\src\com\hello;
HelloWorld.class was put in
F:\workspace\helloWorld\bin\com\hello.
It worked very well in Eclipse. But when I entered the directory “F:\workspace\helloWorld\bin\com\hello” and used command line with “java HelloWorld,” I got NoClassDefFoundError. I know it may have something to do with the classpath. But I’m not quite sure.
Your class is in a package
com.hello. To run it, you must make sure the base directory of the package, which isF:\workspace\helloWorld\binin your case, is in the classpath.Try running it like this:
You can also go to the directory
F:\workspace\helloWorld\binand then run it withThis will work because Java will use the current directory as the default (if you do not have the
CLASSPATHenvironment variable set).