Wednesday, December 3, 2008

Java Compilation Problems (1)

The problem that I am going to address here was resolved by me by accident. When I used to try to run a java file using java filename , I used to get the error :

NoClassDefinitionFoundError filename
It was absolutely irritating. However after about 18 months of struggle(including re-installing my OS several times in that period) I came up with a proper solution

This thing will most probably work provided that u have the proper classpath set as I have mentioned in my previous post. Or else I hope that it should work anyway.

When running or compiling a file use the following-

javac -cp .
java -cp . Filename


javac -classpath .
java -classpath . Filename

What u actually are doing over here is that you are telling the java compiler to search for files in the current directory also (the “.” stands for the current directory) when it tries to compile or or run a java program.

Signing off

No comments: