Tuesday, October 23, 2007

Java classpath issues (Problem 2)

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-installling my os several times in that period) I came up with a proper solution

This thing will most probably work provided that u hav 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 . Filename.java
java -cp . Filename


javac -classpath . Filename.java
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.

No comments: