Search code examples
javaclasspathclassnotfoundexception

How to resolve this error Caused by: java.lang.ClassNotFoundException


I wrote a console application helloworld.java and ran javac helloworld.java,and then java helloworld. This worked fine.

I then created a package com.abc.project and moved helloworld.java into it(the package import statement is correctly generated which is package com.abc.project;). And then i ran javac helloworld.java this worked also fine and generated the class properly.

However, when I ran java com.abc.project.helloworld from the console, it threw an "class not found" error.

Please can anyone advise what is the problem?


Solution

  • Try running

    java -cp ABSOLUTE_PATH com.abc.project.helloworld

    Where ABSOLUTE_PATH refers to the directory where the class files along with packages are present. say it is bin directory where the class files are generated along with same directory structure as source files