Exception in thread "main" java.lang.NoClassDefFoundError: while running .bat file
I have bat file like below with name myBat.bat
1)
@echo off
set CLASSPATH=%CLASSPATH%;C:\Documents and Settings\nchakk\Desktop\3611 java\
javac packbat/inter.java
java packbat.samplepack
pause
2) interface "inter" inside package packbat
package packbat;
public interface inter
{
int i=10;
}
3) my main()class inside package packbat
package packbat;
public class samplepack开发者_JS百科 implements inter
{
public static void main(String s[])
{
System.out.println(i);
}
}
After clicking that .bat file it displays this error:
Exception in thread "main" java.lang.NoClassDefFoundError: packbat/inter Caused by: java.lang.ClassNotFoundException: packbat.inter
How to run that .bat file without error.
You have made a mistake into your mybat.bat.
You don't compile the interface, you must compile the samplepack.java and not the inter.java. Moreover take care about your CLASSPATH because there is space into the PATH. Add quote around like that:
set CLASSPATH=%CLASSPATH%;"C:\Documents and Settings\nchakk\Desktop\3611 java\";
And to finish if you use the "javac packbat/samplepack.java" you must put your mybat.bat into the parent directory of your java files.
Try set "CLASSPATH=%CLASSPATH%;C:\Documents and Settings\nchakk\Desktop\3611 java\"
(put quotes around the path since it contains spaces).
精彩评论