This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes com.sun.mail... no classdef error when sending Mail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "com.sun.mail... no classdef error when sending Mail" Watch "com.sun.mail... no classdef error when sending Mail" New topic
Author

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

Murad Iqbal
Ranch Hand

Joined: Dec 09, 2003
Posts: 90
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

Joined: Dec 09, 2003
Posts: 90
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

Joined: Dec 09, 2003
Posts: 90
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
Sudipta Bhowmik
Greenhorn

Joined: Sep 24, 2004
Posts: 1
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)
hans menon
Greenhorn

Joined: Sep 29, 2004
Posts: 6
Aarrrgghh!!

I have the same problem.

does anyone know the answer?
thanks in advance (I hope)
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Himanshu Bisht
Ranch Hand

Joined: Aug 27, 2004
Posts: 96
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
Christian Andersson
Greenhorn

Joined: Oct 11, 2004
Posts: 1
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

Joined: Aug 27, 2004
Posts: 96
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
D deVera
Greenhorn

Joined: Nov 11, 2004
Posts: 1
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
Suryasish Banerjee
Greenhorn

Joined: Oct 31, 2005
Posts: 1
I have got the same exception.I have all the required jars. But still getting the exception. Can anybody help..??
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14194
    
  20

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Don Adams
Greenhorn

Joined: Nov 16, 2005
Posts: 1
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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
Steve Friend
Greenhorn

Joined: Jan 21, 2006
Posts: 1
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.
Bill White
Ranch Hand

Joined: Oct 27, 2002
Posts: 82
But what if you need J2EE.jar and are still experiencing these problems?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42039
    
  64
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?


Ping & DNS - my free Android networking tools app
Janathr Raveendra
Greenhorn

Joined: Aug 07, 2006
Posts: 1
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.
Erick Frausto
Greenhorn

Joined: Jan 26, 2009
Posts: 1
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..

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Chris Lott
Greenhorn

Joined: Mar 24, 2009
Posts: 3
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
Marshal

Joined: Mar 22, 2005
Posts: 42039
    
  64
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

Joined: Mar 24, 2009
Posts: 3
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
Marshal

Joined: Mar 22, 2005
Posts: 42039
    
  64
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

Joined: Mar 24, 2009
Posts: 3
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
Marshal

Joined: Mar 22, 2005
Posts: 42039
    
  64
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.
Nathan England
Greenhorn

Joined: Jul 13, 2009
Posts: 20
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.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: com.sun.mail... no classdef error when sending Mail