Thursday, May 05, 2005

Java Mail and Google Search API

On one of the projects I'm involved with, we use Java Mail for sending e-mail and the Google search API for indexing our pages. These seemingly unrelated components are in fact connected.

For the longest time we were seeing javax.mail.NoSuchProviderException: No provider for smtp type exceptions. My searches told me that this was most likely because of either a mis-match between my mail.jar and activation.jar files or that I had duplicates of either. I was positive neither was the case. Finally, I removed the JAR files and the code still compiled. We must have had a duplicate after all. After putting together a Perl script to search all the JARs on my classpath, I found that the google-api.jar was in fact the culprit. It includes both the mail and activiation frameworks. So for anyone else who happens to come across this same problem and then subsequently comes across this page (i.e. nobody), now you know what to do.

4 comments:

Martin Davidsson said...

Hey Smita,

I did as I described above, namely I removed the Mail and Activiation related classes from the google.jar file. To do so, I extracted the class files (jar -xf google.jar), removed the relevant classes, and then re-created the jar file (jar -cf google.jar *). I could be off on the jar command's syntax. Does that not help your issue?

Martin Davidsson said...

Odd, I would think that should do it. I don't think I have the Perl script I mentioned anymore, but that might be another debugging technique you could try. For all the .jar files in your classpath, list the classes (jar -tf file.jar) and see where the activation/mail classes show up.

Anonymous said...

Hi all,
I know that this article is a few old, but man, i finished my career final proyect thanks to it and i want to give you my thanks.
I really appreciate the help that you provided to my companion and me with this article.

Thanks

Cyllan

Martin Davidsson said...

Thanks for the kind words and glad it helped you out!