We help IT Professionals succeed at work.

JAVA CLASS NOT FOUND

gaugeta
gaugeta asked
on
Hi Experts...
I have a list of java files which were working perfectly before.
Now when i tried to run the same java file it displayed the message java class not found.
Before running i have set the entire classes being referenced and i have set the current directory into the classpath by:
setenv CLASSPATH ${CLASSPATH}:pwd
I am executing : java packagename.classname.
And the class file is present in the same directory as well.
I dont understand the same thing was working perfectly before.
What is missing here
Please help...
Comment
Watch Question

Top Expert 2016

Commented:
What shell are you using? What does the following print?
echo ${SHELL}

Open in new window

Author

Commented:
@CEHJ: Thanks for replying.
the output of the above command is : /bin/tcsh
Top Expert 2016

Commented:
Try the following or just pass the cp directly to Java
setenv CLASSPATH ${CLASSPATH}:.
export CLASSPATH

Open in new window

Author

Commented:
@CEHJ:Still not working.
I dont understand what can change in one day.
Please help...
Top Expert 2016

Commented:
I need to know what else you're doing really. Of course for the above to be any use whatever, the following needs to be right

echo ${CLASSPATH}

Author

Commented:
@CEHJ: Thanks for the reply.
I add the jars to the path like mail.jsr,log4j,jar...etc.
And when i execute echo ${CLASSPATH}  i see all the jars added to the classpath.
But when i execute it the the java file i get the below message.
The java class is not found:  autoUpload.ftpUpload
Top Expert 2016

Commented:
Please - always post any error messages fully and literally - it just wastes time otherwise
I am executing : java packagename.classname.
And the class file is present in the same directory as well.

If I get it right, there is a problem here. The class file must NOT be in the same directory. It must be in the directory matching package path. For example, for your autoUpload.ftpUpload, you should have the "autoUpload" directory there and you should add the containing directory to the class path. Suppose you have:

/home/user/proj/autoUpload/ftpUpload.class

Then you could run java from /home/user/proj, like this:
cd /home/user/proj
java -cp . autoUpload.ftpUpload

Open in new window

or
cd /home/user/proj
setenv CLASSPATH ${CLASSPATH}:.
export CLASSPATH
java autoUpload.ftpUpload

Open in new window

or, if you want to execute it from anywhere,
java -cp /home/user/proj autoUpload.ftpUpload

Open in new window

Top Expert 2016
Commented:
>>If I get it right, ...

I'm assuming there's nothing of that kind wrong since gaugeta says 'nothing has changed'. Clearly *something* has, but i'm guessing (perhaps incorrectly) that nothing of such a fundamental kind has changed

Author

Commented:
@CEHJ &@stachenov:thanks for the replies.
the .cshrc file profile was modified by someone which was causing the issues.
After restoring the values it works fine.
Thanks for the support...
Top Expert 2016

Commented:
OK. Glad you're fixed