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);
        }
    }
}

While writing a code to send an email across the network i found this code.The jars i use are : javaee-api-5.jar, activation.jar and mail.jar

I compile the code and run it in eclipse.It works fine and sends a mail to the desired mail id but the problem occurs when i try to make a jar file out of it by exporting the jar file i get the warning : Jar exported .Finished with warnings.

The error i get is :

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

What could be the possible reason? Kindly help me find the solution.

Thor
  • 6,607
  • 13
  • 62
  • 96
Phoenix225
  • 167
  • 5
  • 12
  • 1
    http://stackoverflow.com/questions/2591516/why-its-failed-to-load-main-class-manifest-attribute-from-jar-file – Jayan Apr 19 '12 at 09:27
  • Whenever i compile the code i always get MailSender$1.class in the bin apart from the MailSender.class – Phoenix225 Apr 19 '12 at 10:17
  • / Compiled from MailSender.java (version 1.6 : 50.0, super bit) class MailSender$1 extends javax.mail.Authenticator { // Method descriptor #6 ()V // Stack: 1, Locals: 1 MailSender$1(); 0 aload_0 [this] 1 invokespecial javax.mail.Authenticator() [8] 4 return Line numbers: [pc: 0, line: 31] [pc: 4, line: 1] Local variable table: [pc: 0, pc: 5] local: this index: 0 type: new MailSender(){} // Method descriptor #15 ()Ljavax/mail/PasswordAuthentication; // Stack: 4, Locals: 1 protected javax.mail.PasswordAuthentication – Phoenix225 Apr 19 '12 at 10:21
  • getPasswordAuthentication(); 0 new javax.mail.PasswordAuthentication [16] 3 dup 4 ldc [18] 6 ldc [20] 8 invokespecial javax.mail.PasswordAuthentication(java.lang.String, java.lang.String) [22] 11 areturn Line numbers: [pc: 0, line: 33] Local variable table: [pc: 0, pc: 12] local: this index: 0 type: new MailSender(){} Inner classes: [inner class info: #1 MailSender$1, outer class info: #0 inner name: #0, accessflags: 0 default] – Phoenix225 Apr 19 '12 at 10:21
  • Enclosing Method: #28 #30 MailSender.main([Ljava/lang/String;) – Phoenix225 Apr 19 '12 at 10:21
  • I have copy pasted the contents of the MailSender$1 file being created – Phoenix225 Apr 19 '12 at 10:22

1 Answers1

0

Yes, a manifest file should be created. This file contains one-line text file with a "Main-Class" e.x: Main-Class: Your Main class

Or you can use eclipse to do that: Java: export to an .jar file in eclipse

Community
  • 1
  • 1
Vu.N
  • 149
  • 4