how can i run java program from any where

Hello all sorry didnt know where to post it
i compiled simple program that using "System.getProperty("user.dir");"
now i compiled the program under directory foo and and its running great when i do "java myapp"
i included this directory in the $PATH env variable so i could see it fro any where in the system
but now when i try to run this java app from other place in the file system with "java myapp" it gives me "Exception in thread "main" java.lang.NoClassDefFoundError:" erorr . why is that ?
Thanks

You have to set the CLASSPATH

or specify the classpath at runtime like

java -cp /local/foo classfile