3 Replies - 8264 Views - Last Post: 18 August 2010 - 11:07 PM Rate Topic: -----

#1 tedy2808  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-August 10

Exception in thread "main" java.lang.NoClassDefFoundError: jav

Posted 18 August 2010 - 02:27 AM

hi all,
need your help..

i'm trying to run code in one of the tutorial but below are the error message i received:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException

below are the script:

 import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class testjava {

public static final String MAIL_SERVER = "smtp.gmail.com";
public static final String USERNAME = "my_own_email@gmail.com";
public static final String PASSWORD = "my_password";

public static void main(String[] args) {
try {
String fromAddress = "my_own_email@gmail.com";
String toAddress = "recipient_email@gmail.com";
String subject = "This is a test Message";
String message = "Hello Hows u?";

Properties properties = System.getProperties();
properties.put("mail.smtps.host", MAIL_SERVER);
properties.put("mail.smtps.auth", "true");

Session session = Session.getInstance(properties);
MimeMessage msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(fromAddress));
msg.addRecipients(Message.RecipientType.TO, toAddress);
msg.setSubject(subject);
msg.setText(message);

Transport tr = session.getTransport("smtps");
tr.connect(MAIL_SERVER, USERNAME, PASSWORD);
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
} catch (AddressException ex) {
System.out.println(ex.getMessage());
} catch (MessagingException ex) {
System.out.println(ex.getMessage());
}
}
}





i did add my class path and below are my class path:
  /opt/java1.5/bin/javac -classpath ".:/usr/local/jdk/lib/classes.zip:/my_var/the_batch/SQL_var/lib/mssqlserver.jar:/my_var/the_batch/SQL_var/lib/msbase.jar:/my_var/the_batch/SQL_var/lib/msutil.jar:/my_var/the_batch/SQL_var/lib/classes12.jar:/my_var/the_batch/SQL_var/lib/nls_charset12.jar:/my_var/the_batch/SQL_var/lib/ojdbc14.jar:/my_var/the_batch/SQL_var/lib/mail.jar:/my_var/the_batch/SQL_var/lib/jaf-1.0.2/activation.jar" testjava.java
  




p/s:the additional class path is for my testing (for other script).

Anyone can explain to me why i got the error message?

thanks in advanced :)

This post has been edited by tedy2808: 18 August 2010 - 10:48 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Exception in thread "main" java.lang.NoClassDefFoundError: jav

#2 aamir.ramzan  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 28
  • Joined: 12-January 10

Re: Exception in thread "main" java.lang.NoClassDefFoundError: jav

Posted 18 August 2010 - 02:53 AM

I think you need to add the mail.jar files in the lib folder.
You can find the mail.jar file over here.mail.jar or try this one. http://java.sun.com/products/javamail/

I think you need to add the mail.jar files in the lib folder.
You can find the mail.jar file over here.mail.jar or try this one. http://java.sun.com/products/javamail/
Was This Post Helpful? 0
  • +
  • -

#3 tedy2808  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-August 10

Re: Exception in thread "main" java.lang.NoClassDefFoundError: jav

Posted 18 August 2010 - 10:50 PM

i added in the run.sh and compile.sh for mail.jar and activation.jar ...as u can see above in the 2nd code..But i still having the same problem..i i have to copy the entire file or only mail.jar and activation.jar?
Was This Post Helpful? 0
  • +
  • -

#4 aamir.ramzan  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 28
  • Joined: 12-January 10

Re: Exception in thread "main" java.lang.NoClassDefFoundError: jav

Posted 18 August 2010 - 11:07 PM

There is README.txt in the zipped folder. Did you follow that?



Requirements
------------

Note that the JavaMail API requires the JavaBeans™ Activation
Framework package to be installed as well if you're using JDK 1.5
or earlier. Download the latest version of the JavaBeans Activation
Framework from

http://java.sun.com/...lasgow/jaf.html

and install it in a suitable location.


Installation
------------

UNIX/Linux
----------

1. Unzip the javamail1_4_3.zip archive.
(You may have already done this.)

2. Set your CLASSPATH to include the "mail.jar" file obtained from
the download, as well as the current directory.

Assuming you unzipped javamail1_4_3.zip in /u/me/download/ the
following would work:

export CLASSPATH=$CLASSPATH:/u/me/download/javamail-1.4.3/mail.jar:.

Also, if you're using JDK 1.5 or earlier, include the
"activation.jar" file that you obtained from downloading the
JavaBeans Activation Framework, in your CLASSPATH. For example:

export CLASSPATH=$CLASSPATH:/u/me/download/activation/activation.jar


3. Go to the demo directory

4. Compile any demo using your Java compiler. For example:

javac msgshow.java
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1