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");

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

	public static void main(String args[])
	test5 obj = new test5();

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

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

peter_budo commented: First time poster using code tags, well done. +13

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.