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


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

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

  1. #1
    Join Date
    May 2004
    Posts
    7

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

    Hi
    I just installed java's sdk 1.4.2_04 and had a few problems getting the hello world sample to work even though I had set the Path variable correctly, got some advice that mentioned I should include the -cp switch before running sample and it did work. But I have downloaded Java's Mail API and the Jaf package required to enable the Mail API to work. I set the ClassPath correctly as the instruction guide instructed but when i tried running a test application it compiled correctly but did run, instead returned the following error.
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException.
    Here is the code I was running
    import javax.mail.*;
    import java.util.Properties;
    import javax.mail.internet.*;

    public class Test {

    public static void main(String[] args)
    {
    Properties props = new Properties();
    //set mail server
    props.put("mail.stmp.host","localhostgoeshere");
    //create session
    Session session = Session.getDefaultInstance(props,null);
    //error throwing code
    try
    {
    System.out.println("Create Mime");
    MimeMessage message = new MimeMessage(session);
    //fill in addressing info
    message.setFrom(new InternetAddress("bob_burns@mail.com"));
    System.out.println("Set From");
    message.addRecipient(Message.RecipientType.TO,new InternetAddress("bob_burns@mail.com"));
    message.setSubject("Testing Mail Merge");
    message.setText("It works! Hello World");
    //send message
    System.out.println("Sending Mesage");
    // Transport.send(message);
    System.out.println("Message Sent!!");
    }//end of try
    catch(AddressException ae)
    {
    ae.printStackTrace();
    }
    catch(MessagingException me)
    {
    me.printStackTrace();
    }//end of catch
    }//end of main

    }//end of class
    Please help!

  2. #2
    Join Date
    Feb 2004
    Posts
    808
    your classpath is set incorrectly. to write programs that use mail, this is my classpath. you should modify the path to the mail JAR file if you are running a different version or have installed to a different place:

    CLASSPATH=c:\j2sdk1.4.2_03\jre\lib\rt.jar;c:\javamail1.3.1\mail.jar;c:\jaf1.0.2\activation .jar;.

    this is the classpath on my system as a result of running the SET dos command. to set the classpath variable permanently (advised) follow the instructions here:
    http://www.microsoft.com/resources/d...variables.mspx

    add variable name CLASSPATH
    variable value: c:\j2sdk1.4.2_03\jre\lib\rt.jar;c:\javamail1.3.1\mail.jar;c:\jaf1.0.2\activation.jar;.
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center