This code is compile fine, but whenever I try to run, it gives an error says NoClassDefFound. What is the possible reason and solution, please explain.
package myPack;
public class PasswordVerification
{
public boolean verify(String usrId, String pass)
{
if(usrId.equals("pranjut")&&pass.equals("password"))
{
return true;
}else
{
return false;
}
}
public static void main(String [] main)
{
PasswordVerification vp=new PasswordVerification();
System.out.println(vp.verify("pranjut","password"));
}
}
解决方案
Make sure you are in the directory that contains the myPack folder. You should not be within the myPack folder. I just tried it on my linux machine and it looks like it automatically included the working folder in the classpath, but only if the CLASSPATH environment variable is NOT set. If it is set, then you should either add the current folder to it, or specify the classpath on the command line as follows:
java -cp . myPack.PasswordVerification