0
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailSender {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        final String username = "xxx.xxxx@xxx.com";
        final String password = "xxxo@xxxx";

        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "webmxzz.xxxxxxx.com");
        props.put("mail.smtp.port", "587");

        Session session = Session.getInstance(props,
          new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
          });

        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("xxxx.x@xxxx.com"));
            message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("xxxx.x@xxxx.com"));
            message.setSubject("Testing Subject");
            message.setText("Dear User,"
                + "\n\n No spam to my email, please!");

            Transport.send(message);

            System.out.println("Done");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
}

ネットワーク経由で電子メールを送信するコードを書いているときに、このコードを見つけました。私が使用する jar は :javaee-api-5.jaractivation.jarmail.jar

コードをコンパイルしてEclipseで実行します。問題なく動作し、目的のメールIDにメールを送信しますが、jarファイルをエクスポートしてjarファイルを作成しようとすると、警告が表示されます:Jar export.警告で終了。

私が得るエラーは次のとおりです。

Could not find the main class: (class). Program will exit.

考えられる理由は何ですか?解決策を見つけるのを手伝ってください。

4

1 に答える 1

0

はい、マニフェスト ファイルを作成する必要があります。このファイルには、「Main-Class」を含む 1 行のテキスト ファイルが含まれています。例: Main-Class: Your Main class

または、Eclipse を使用してそれを行うこともできます: Java: Eclipse で .jar ファイルにエクスポートします。

于 2012-04-19T09:35:44.130 に答える