如何在NetBeans中查看完整输出错误消息

时间:2014-03-21 12:56:22

标签: java netbeans javamail

我成功构建了代码,然后遇到了问题。

这是我的代码:

package EmailSending;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class launcher {
    public static void main(String[] args){

      final String username = "my-email@yandex.ru";
      final String password = "my-password";

      String to = "to-email@mail.ru";

      String from = "from-email@yandex.ru";

      String host = "localhost";

      Properties properties = System.getProperties();
      properties.put("mail.smtp.auth", "true");
      properties.put("mail.smtp.starttls.enable", "true");
      properties.put("mail.smtp.host", host);

      Session session = Session.getInstance(properties);

      try{

         MimeMessage message = new MimeMessage(session);

         message.setFrom(new InternetAddress(from));

         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         message.setSubject("This is the Subject Line!");

         message.setText("This is actual message");

         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}


此行有错误:
Session session = Session.getInstance(properties);

这是输出消息:

run:
    Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
    at javax.mail.Session.initLogger(Session.java:227)
    at javax.mail.Session.<init>(Session.java:212)
    at javax.mail.Session.getInstance(Session.java:265)
    at EmailSending.launcher.main(launcher.java:34)
    Caused by: java.lang.ClassNotFoundException: com.sun.mail.util.MailLogger
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 4 more
Java Result: 1



如何在NetBeans中查看完整输出错误消息?如何扩展&#34; ... 4更多&#34;?

1 个答案:

答案 0 :(得分:1)

如果您没有弄明白,该异常的原因是您没有将正确的JavaMail库添加到您的项目中。请参阅this JavaMail FAQ entry

如果您正在使用Maven,您可能需要参考列出的{MMSMail坐标here。你想要com.sun.mail:javax.mail