1,105,169 Community Members

java.lang.NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream

Member Avatar
Pritha17
Newbie Poster
1 post since Apr 2010
Reputation Points: 13 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
1
 

hello, I'm using eclipse platform to try to transfer file using Java mail API, but facing the following exception

java.lang.NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream

I know this is a common problem, but i've tried all possible measures to get rid of this exception

here's what i tried
* I downloaded javamail-1.4.3 from sun site, and copied mail.jar and activation.jar to my classpath java/jre6/lib/ext

* i noticed there's no SharedByteArrayInputStream in mail/util, so i modified my jar file by copying this missing class from javax/mail/util to com/sun/mail/util/, and added it to classpath again, but the error persists.

* i also imported archive(both .jar files) into my project, but no use.

import javax.mail.*;
import javax.mail.event.TransportListener;
import javax.mail.event.TransportEvent;
import javax.mail.internet.*;
import java.util.Properties;
import javax.activation.*;

 
class test5 {
	private String mailHost="smtp.gmail.com";
	private String body;
	private String myFile="C:\\sample_text.docx";
 
	private Properties props;
	private Session mailSession;
	
 
	private MimeMessage message;
	private InternetAddress sender;
 
	private Multipart mailBody;
	private MimeBodyPart mainBody;
	private MimeBodyPart mimeAttach;
 
	private DataSource fds;
 
 
	void fun()
	{
		//Creating a Session
		props=new Properties();
                props.put("mail.transport.protocol", "smtp");
		props.put("mail.smtp.host", mailHost);
		props.put("mail.smtp.port", "25");
		props.put("mail.smtp.auth", "true");
	    props.put("mail.smtp.starttls.enable","true");

 
		mailSession=Session.getDefaultInstance(props, new MyAuthenticator());
 	
		message=new MimeMessage(mailSession);
		mailBody=new MimeMultipart();

	}
 
	
	public static void main(String args[])
	{
	test5 obj = new test5();
	obj.fun();
	
	}
	
	}


class MyAuthenticator extends Authenticator
{
	MyAuthenticator()
	{
		super();
	}
 
	protected PasswordAuthentication getPasswordAuthentication()
	{
		return new PasswordAuthentication("myusername", "mypassword");
	}
}

how should i resolve this problem????
Please help.

Member Avatar
parry_kulk
Junior Poster
166 posts since Jan 2007
Reputation Points: 14 [?]
Q&As Helped to Solve: 41 [?]
Skill Endorsements: 0 [?]
Team Colleague
 
0
 

First of all I would suggest that you should not change 3rd party jar files as its difficult to gauge the side effects of the change.

The class SharedByteArrayInputStream is part of the package javax.mail.util from javamail 1.4
There might be some other jar file in the classpath (like j2ee.jar, weblogic.jar) which is refering older javamail implementation and hence causing the exception. Try finding it.
You can also try placing the mail.jar file at the top of order in the classpath

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article