• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

com.sun.mail... no classdef error when sending Mail

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, when I am creating the MimeMessage, i am getting this exception. I am passing it the session which was creating using a properties object that had mail.smtp.host value. what can be the issue? where do i find this SharedByteArrayInputStream class?

java.lang.NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream
com.handler.EmailCommand.processTestEmail(Unknown Source)
com.handler.EmailCommand.execute(Unknown Source)
com.servlet.BtmAdminServlet.processRequestType(Unknown Source)
com.servlet.BtmAdminServlet.doPost(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:768)
javax.servlet.http.HttpServlet.service(HttpServlet.java:861)
 
Murad Iqbal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is what i am getting now. i copied the new mail.jar in the url.

java.lang.NoClassDefFoundError: com/sun/activation/registries/LogSupport
javax.activation.MailcapCommandMap.<init>(MailcapCommandMap.java:111)
javax.activation.CommandMap.getDefaultCommandMap(CommandMap.java:44)
javax.activation.DataHandler.getCommandMap(DataHandler.java:136)
javax.activation.DataHandler.getDataContentHandler(DataHandler.java:567)
javax.activation.DataHandler.writeTo(DataHandler.java:294)
javax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:230)
javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1065)
javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:1923)
javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1904)
javax.mail.Transport.send(Transport.java:79)
com.handler.EmailCommand.processTestEmail(Unknown Source)
com.handler.EmailCommand.execute(Unknown Source)
com.servlet.BtmAdminServlet.processRequestType(Unknown Source)
com.servlet.BtmAdminServlet.doPost(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:768)
javax.servlet.http.HttpServlet.service(HttpServlet.java:861)
 
Murad Iqbal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i copied the new mail.jar in the classpath and the first exception was gone, however there was another one, which i have written in the 2nd post. probably i should place another .jars
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i had also facing the same problem : how did you sl;ove it.
java.lang.NoClassDefFoundError: com/sun/activation/registries/LogSupport
at javax.activation.MailcapCommandMap.<init>(MailcapCommandMap.java:111)
at javax.activation.CommandMap.getDefaultCommandMap(CommandMap.java:44)
at javax.activation.DataHandler.getCommandMap(DataHandler.java:136)
at javax.activation.DataHandler.getDataContentHandler(DataHandler.java:567)
at javax.activation.DataHandler.writeTo(DataHandler.java:294)
at javax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:230)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1065)
at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:1923)
at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1904)
at javax.mail.Transport.send(Transport.java:79)
at com.bls.utils.TestMail.postMail(TestMail.java:51)
at com.bls.utils.TestMail.main(TestMail.java:61)
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aarrrgghh!!

I have the same problem.

does anyone know the answer?
thanks in advance (I hope)
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you read the JavaMail documentation you will notice that JavaMail needs the JavaBeans Activation Framework (JAF) to work. So you'll have to include that on your classpath too.
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the activation.jar 's is missing in the classpath.

either set classpath for the file or put it inside

//jdkdir/lib/ext/


if u don't have activation.jar download it from sun
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I now have the activation.jar in my classpath but am still getting the same exception. Looking in the jar file I see that the class "com/sun/activation/registries/LogSupport" actually does not exist in the activation package.

I'm using the latest jaf package (1.0.2).
 
Himanshu Bisht
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
download it from sun site.
I don't know what exactly the problem is but i am sure the answer is in claspath.
U give the classpath u have set.

himanshu
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure if anyone has found a solution to this, but i had the same problem. I downloaded the latest javamail and activation from the sun site, ran the examples and it worked fine. Used the same test file in my project and ran into the same error.

Found a work around to the solution by deleting the activation package in the j2ee.jar file.

Not sure why though, I read in another forum that the same error occurs in java 5 though.

Good luck

~ Dave
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have got the same exception.I have all the required jars. But still getting the exception. Can anybody help..??
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Suryasish Banerjee:
I have got the same exception.I have all the required jars. But still getting the exception. Can anybody help..??


Make sure your classpath is set correctly.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. I've had all of the same problems listed on
this page. The answer is that the mail.jar and
the activation.jar need to be in your classpath
like this:

java -classpath ./mail.jar:./activation.jar:. SendApp

This assumes your application is called SendApp
and mail.jar and activation.jar are in the same
directory as SendApp and you issue the java command
in that directory.

However, the error occurs if the j2ee.jar is also included
in your classpath. When the j2ee.jar is included,
then I get the
java.lang.NoClassDefFoundError: com/sun/activation/registries/LogSupport
error.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since JavaMail is supposed to be part of J2EE, if you have j2ee.jar in your classpath you should not need either of mail.jar and activation.jar in your classpath. Having them there opens you up to the possibility of conflicts between different versions.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I verified Don's solution
The problem occurs if j2ee.jar is on the classpath
Remove j2ee.jar from the classpath and all is OK,
You should have activation.jar and mail.jar on the classpath

Thanks Don.


I'm afraid someone confused the email thread, by saying that
j2ee.jar contains all classes you need, this isnt correct.

Just use mail.jar and activation.jar, and all is OK.

mail.jar is from suns email.

Also, I use Apache James, to test sending receiving email - its soooo
easy.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But what if you need J2EE.jar and are still experiencing these problems?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of using j2ee.jar, I prefer to add the jar files for the various APIs one by one, precisely so that I can update them individually. Is there anything in j2ee.jar that you can't add otherwise?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use mail.jar and activation.jar in your classpath instead of j2ee.jar.
Then all problems will slove and you can send mail without any exceptions.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the following situation:

In order to send mails, I needed to use mail.jar and activation.jar, but for other reasons, I needed to use the j2ee.jar too. I tried with different versions of the jars and with different combinations, but I always found problems.

My solution was the following:

Firts, I was running my code into my IDE (IBM Rational) and I didn't have any problems here, the problem was when I ran my code outside of my IDE. I decided to search for the libraries (mail.jar and activation.jar) that my IDE was using, I found that it was using these libraries with some modifications and with different names (mail-impl.jar and activation-impl.jar), then I put them into my classpath instead the original libraries and my code started to run without any problems!!

Greetings from Mexico..

 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for your input.

However, did you notice the last post was almost 2.5 years old? That usually means nobody is interested anymore, and it's quite possible that some of the posters in this thread are no longer active here.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recently hit the same problem: java.lang.NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream. I was trying to use javamail in an application that uses classloaders etc. much like an appserver. I added activation.jar and mail.jar to my project. When I launched my POJO test harness the trivial mail sender worked great. When the same method ran inside the classloade-d application the trivial mail sender generated the exception shown above. After some searching I hit this discussion, thanks much for the tip to take a hard look at j2ee.jar. I found that if I deleted the j2ee.jar from my app's lib library, the email could be sent just fine, no more exception. Of course without the j2ee classes, other parts of the app broke. The solution I hit was to download a reasonably current J2EE library, now called javaee.jar, to replace the old j2ee.jar. My application that depends on j2ee functionality works with the new one, and better yet the email sender also works. So in the end I think this was just a version mismatch problem among jars. The old j2ee jar definitely has activation *and* mail components in it. I can only guess that those components didn't play nicely with the new ones from activation.jar and mail.jar. Hope this info helps someone.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chris, welcome to JavaRanch.

I think the old j2ee.jar only had the actual API classes (javax.activation.* and javax.mail.*) but not the implementation classes (com.sun.mail.*). Reading your post it seems that that has changed with javaee.jar.

Reading my old post above, I still prefer the approach I mentioned then - JavaMail has seen two updates since it was incorporated into JEE 5, addressing more than 50 bugs and issues. The average JavaMail application may not run into those, but it's something to consider.

Either way, good to hear you found a solution.
 
Chris Lott
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf, you mention adding API jars individually. Sounds straightforward but I don't want to open a new can of worms. Are the components within the j2ee (now javaee) jar available separately as proper distributions that have been tested together, or did you just jar -xf then jar -cf the classes you wanted from j2ee.jar?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chris Lott wrote:Are the components within the j2ee (now javaee) jar available separately as proper distributions that have been tested together, or did you just jar -xf then jar -cf the classes you wanted from j2ee.jar?


The APIs are available separately, but there isn't much testing to be done, as they're really independent of each other. If you go to java.sun.com you'll find individual downloads for EJB, JavaMail, JMS, JMX, JAAS, JNDI etc. And no, I wouldn't want to munge around with the individual files. That's a recipe for problems down the road, I think.
 
Chris Lott
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. After removing javaee.jar from the classpath, suffering thru a few class-not-found exceptions, and googling wildly I discovered I only needed EJB and JTA. Both of those are available separately from Sun. JTA classes arrive in a zip archive instead of a jar file; works the same I know but just seemed weird. One thing that still drives me nuts is how to tell what version of Java (I think the newfangled name is "Platform") is required to use a given package from Sun. I'm stuck on 1.5 just bcos that's what my customer still has on its desktops. It sure would be nice if the download pages at sun listed prereqs, like "Java 1.3" or "Java 1.999999" :-)
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I fairly certain that there isn't any API from Sun that requires Java 6 yet, so you should be fine. I'm using Java 5 myself, and haven't felt constrained in any way so far.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I encountered the same problem in my Rational IDE.

To solve this, I went to properties->Java Build Path-> Order and Export
and I moved both mail.jar and activation.jar above the j2ee.jar. This seems to have resolved the problem in my IDE.

 
reply
    Bookmark Topic Watch Topic
  • New Topic