繁体   English   中英

jar和未找到类定义错误

[英]jar and No Class definition found error

我已经创建了一个用于发送邮件的Java程序,并且导入了一些与该程序相关的软件包。 我下载了包javax.mailjavax.activation并将其放入C:\\ Program Files \\ Java \\ jdk1.7.0 \\ jre \\ lib \\ ext

我先编译程序,然后编译,但是运行时会抛出异常。 在此处输入图片说明

我不明白为什么它会引发异常。

我的代码在这里。

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.net.*;

public class SendEmail
{

   public static void main(String [] args)
   {    
      // Recipient's email ID needs to be mentioned.
      String to = "rs.89.rj@gmail.com";

      // Sender's email ID needs to be mentioned
      String from = "manoj1990gupta@yahoo.in";
        try{
      // Assuming you are sending email from localhost
      String host = InetAddress.getLocalHost().toString();

      // Get system properties
      Properties properties = System.getProperties();

      // Setup mail server
      properties.setProperty("mail.smtp.host", host);

      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);

      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);

         // Set From: header field of the header.
         message.setFrom(new InternetAddress(from));

         // Set To: header field of the header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         // Set Subject: header field
         message.setSubject("This is the Subject Line!");

         // Now set the actual message
         message.setText("This is actual message");

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

您需要下载JavaMail API软件包并将其放入类路径中,但请确保将mail.jar以及可以在lib文件夹中找到的所有从属库包含在内。

要从命令行设置类路径:

java -cp "mail.jar;lib/*" SendEMail

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM