簡體   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