i have the code for a simple mail transfer protocol but when i go to compile it in eclipse i get an error along the lines of cant find "main" class, program will now terminate, ive attached the code and would love it if someone could take a look and see if ive messed something up or if its just eclipse being a pain

Envelope.java

MailClient.java

Message.java

SMTPConnection.java

Attachments
import java.io.*;
import java.net.*;
import java.util.*;

/* $Id: Envelope.java,v 1.8 1999/09/06 16:43:20 kangasha Exp $ */

/**
 * SMTP envelope for one mail message.
 *
 * @author Jussi Kangasharju
 */

public class Envelope {/* SMTP-sender of the message (in this case, contents of From-header. */
    public String Sender;

    /* SMTP-recipient, or contents of To-header. */
    public String Recipient;

    /* Target MX-host */
    public String DestHost;
    public InetAddress DestAddr;

    /* The actual message */
    public Message Message;

    /* Create the envelope. */
    public Envelope(Message message, String localServer) throws UnknownHostException {
        /* Get sender and recipient. */
        Sender = message.getFrom();
        Recipient = message.getTo();

        /* Get message. We must escape the message to make sure that 
           there are no single periods on a line. This would mess up
           sending the mail. */
        Message = escapeMessage(message);

        /* Take the name of the local mailserver and map it into an
         * InetAddress */
        DestHost = localServer;
        try {
            DestAddr = InetAddress.getByName(DestHost);
        } catch (UnknownHostException e) {
            System.out.println("Unknown host: " + DestHost);
            System.out.println(e);
            throw e;
        }
        return;
    }

    /* Escape the message by doubling all periods at the beginning of
       a line. */
    private Message escapeMessage(Message message) {
        String escapedBody = "";
        String token;
        StringTokenizer parser = new StringTokenizer(message.Body, "\n", true);

        while(parser.hasMoreTokens()) {
            token = parser.nextToken();
            if(token.startsWith(".")) {
                token = "." + token;
            }
            escapedBody += token;
        }
        message.Body = escapedBody;
        return message;
    }

    /* For printing the envelope. Only for debug. */
    public String toString() {
        String res = "Sender: " + Sender + '\n';
        res += "Recipient: " + Recipient + '\n';
        res += "MX-host: " + DestHost + ", address: " + DestAddr + '\n';
        res += "Message:" + '\n';
        res += Message.toString();
        
        return res;
    }


}
import java.io.*;
import java.awt.*;
import java.awt.event.*;

/* $Id: MailClient.java,v 1.7 1999/07/22 12:07:30 kangasha Exp $ */

/**
 * A simple mail client with a GUI for sending mail.
 *
 * @author Jussi Kangasharju
 */

public class MailClient extends Frame {/* The stuff for the GUI. */
    private Button btSend = new Button("Send");
    private Button btClear = new Button("Clear");
    private Button btQuit = new Button("Quit");
    private Label serverLabel = new Label("Local mailserver:");
    private TextField serverField = new TextField("", 40);
    private Label fromLabel = new Label("From:");
    private TextField fromField = new TextField("", 40);
    private Label toLabel = new Label("To:"); 
    private TextField toField = new TextField("", 40);
    private Label subjectLabel = new Label("Subject:");
    private TextField subjectField = new TextField("", 40);
    private Label messageLabel = new Label("Message:");
    private TextArea messageText = new TextArea(10, 40);

    /**
     * Create a new MailClient window with fields for entering all
     * the relevant information (From, To, Subject, and message).
     */
    @SuppressWarnings("deprecation")
	public MailClient() {
        super("Java Mailclient");
        
        /* Create panels for holding the fields. To make it look nice,
           create an extra panel for holding all the child panels. */
        Panel serverPanel = new Panel(new BorderLayout());
        Panel fromPanel = new Panel(new BorderLayout());
        Panel toPanel = new Panel(new BorderLayout());
        Panel subjectPanel = new Panel(new BorderLayout());
        Panel messagePanel = new Panel(new BorderLayout());
        serverPanel.add(serverLabel, BorderLayout.WEST);
        serverPanel.add(serverField, BorderLayout.CENTER);
        fromPanel.add(fromLabel, BorderLayout.WEST);
        fromPanel.add(fromField, BorderLayout.CENTER);
        toPanel.add(toLabel, BorderLayout.WEST);
        toPanel.add(toField, BorderLayout.CENTER);
        subjectPanel.add(subjectLabel, BorderLayout.WEST);
        subjectPanel.add(subjectField, BorderLayout.CENTER);
        messagePanel.add(messageLabel, BorderLayout.NORTH);     
        messagePanel.add(messageText, BorderLayout.CENTER);
        Panel fieldPanel = new Panel(new GridLayout(0, 1));
        fieldPanel.add(serverPanel);
        fieldPanel.add(fromPanel);
        fieldPanel.add(toPanel);
        fieldPanel.add(subjectPanel);

        /* Create a panel for the buttons and add listeners to the
           buttons. */
        Panel buttonPanel = new Panel(new GridLayout(1, 0));
        btSend.addActionListener(new SendListener());
        btClear.addActionListener(new ClearListener());
        btQuit.addActionListener(new QuitListener());
        buttonPanel.add(btSend);
        buttonPanel.add(btClear);
        buttonPanel.add(btQuit);
        
        /* Add, pack, and show. */
        add(fieldPanel, BorderLayout.NORTH);
        add(messagePanel, BorderLayout.CENTER);
        add(buttonPanel, BorderLayout.SOUTH);
        pack();
        show();
    }

    static public void main(String argv[]) {
        new MailClient();
    }

    /* Handler for the Send-button. */
    class SendListener implements ActionListener {
        public void actionPerformed(ActionEvent event) {
            System.out.println("Sending mail");
            
            /* Check that we have the local mailserver */
            if ((serverField.getText()).equals("")) {
                System.out.println("Need name of local mailserver!");
                return;
            }

            /* Check that we have the sender and recipient. */
            if((fromField.getText()).equals("")) {
                System.out.println("Need sender!");
                return;
            }
            if((toField.getText()).equals("")) {
                System.out.println("Need recipient!");
                return;
            }

            /* Create the message */
            Message mailMessage = new Message(fromField.getText(), 
                                              toField.getText(), 
                                              subjectField.getText(), 
                                              messageText.getText());

            /* Check that the message is valid, i.e., sender and
               recipient addresses look ok. */
            if(!mailMessage.isValid()) {
                return;
            }

            /* Create the envelope, open the connection and try to send
               the message. */
            
            
            try {
            	Envelope envelope = new Envelope(mailMessage, serverField.getText());
                SMTPConnection connection = new SMTPConnection(envelope);
                connection.send(envelope);
                connection.close();
            } catch (IOException error) {
                System.out.println("Sending failed: " + error);
                return;
            }
            System.out.println("Mail sent succesfully!");
        }
    }

    /* Clear the fields on the GUI. */
    class ClearListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Clearing fields");
            fromField.setText("");
            toField.setText("");
            subjectField.setText("");
            messageText.setText("");
        }
    }

    /* Quit. */
    class QuitListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    }


}
import java.util.*;
import java.text.*;

/* $Id: Message.java,v 1.5 1999/07/22 12:10:57 kangasha Exp $ */

/**
 * Mail message.
 *
 * @author Jussi Kangasharju
 */

public class Message {/* The headers and the body of the message. */
    public String Headers;
    public String Body;

    /* Sender and recipient. With these, we don't need to extract them
       from the headers. */
    private String From;
    private String To;

    /* To make it look nicer */
    private static final String CRLF = "\r\n";

    /* Create the message object by inserting the required headers from
       RFC 822 (From, To, Date). */
    public Message(String from, String to, String subject, String text) {
        /* Remove whitespace */
        From = from.trim();
        To = to.trim();
        Headers = "From: " + From + CRLF;
        Headers += "To: " + To + CRLF;
        Headers += "Subject: " + subject.trim() + CRLF;

        /* A close approximation of the required format. Unfortunately
           only GMT. */
        SimpleDateFormat format = 
            new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'");
        String dateString = format.format(new Date());
        Headers += "Date: " + dateString + CRLF;
        Body = text;
    }

    /* Two functions to access the sender and recipient. */
    public String getFrom() {
        return From;
    }

    public String getTo() {
        return To;
    }

    /* Check whether the message is valid. In other words, check that
       both sender and recipient contain only one @-sign. */
    public boolean isValid() {
        int fromat = From.indexOf('@');
        int toat = To.indexOf('@');

        if(fromat < 1 || (From.length() - fromat) <= 1) {
            System.out.println("Sender address is invalid");
            return false;
        }
        if(toat < 1 || (To.length() - toat) <= 1) {
            System.out.println("Recipient address is invalid");
            return false;
        }
        if(fromat != From.lastIndexOf('@')) {
            System.out.println("Sender address is invalid");
            return false;
        }
        if(toat != To.lastIndexOf('@')) {
            System.out.println("Recipient address is invalid");
            return false;
        }       
        return true;
    }
    
    /* For printing the message. */
    public String toString() {
        String res;

        res = Headers + CRLF;
        res += Body;
        return res;
    }


}
import java.net.*;   
 import java.io.*;   
 import java.util.*;   
public class SMTPConnection {  /* The socket connected to server*/   
     private Socket connection;   
     /*streams for reading and writing the socket*/   
     private BufferedReader fromServer;   
    private DataOutputStream toServer;   
        
     /* BASE 64 decode*/   
    //private String username = "MDM2MTEwOA==";   
     //private String pass = "MTk4NDcyNg==";   
        
     /* static final data*/   
     private String server = "localhost";   
     private int port = 25;   
     private static final String CRLF = "\r\n";   
     /* flag to sigh whether connected */   
     private boolean connected = false;   
     /* create an SMTPConnection object.Create the socket and the associated  
      * streams.  
      * constructor  
      */   
     public SMTPConnection (Envelope envelope)throws IOException{   
            
         /*set up the connection and in out streams */   
         try{   
         if(connected==false){   
             connection = new Socket (server,port);   
         }      
         fromServer = new BufferedReader(   
                 new InputStreamReader(connection.getInputStream()));   
         toServer = new DataOutputStream(connection.getOutputStream());   
         }   
        catch(IOException ex){   
             System.out.print(ex);   
             throw ex;   
         }   
         /* check the reply code*/   
         String reply = fromServer.readLine();   
         int code = parseReply(reply);   
         if(code != 220){   
             throw new IOException();   
         }   
         //String localhsot = "137.142.101.120";   
         sendCommand("HELO "+server,250);   
         //sendCommand("AUTH LOGIN "+username,334);   
         //sendCommand(pass,235);   
         connected = true;   
     }   
     /**  
      * send the message  
      * @param envelope envelope contain all the message   
      * @throws IOException   
      */   
     public void send(Envelope envelope)throws IOException{   
         /*  
          * send the message using sendcommand  
          */   
         String command = "MAIL FROM: " + envelope.Sender;   
        sendCommand(command,250);   
         command = "RCPT TO: " + envelope.Recipient;   
         sendCommand(command,250);   
         command = "DATA " + CRLF;   
         sendCommand(command,354);   
         command = "Subject:"+envelope.Message.Headers+CRLF;   
            
         command += envelope.Message.Body+CRLF+"."+CRLF;   
         sendCommand(command,250);   
            
     }   
     /**  
      * close the connection   
      *  
      */   
     public void close(){   
         try{   
             sendCommand("QUIT",221);   
             connection.close();   
             connected = false;   
         }catch(Exception e){   
             System.out.println("COLOSE FAILED...");   
         }   
            
     }   
     /**  
      * send an smtp command to the server and checke the reply code   
      * @param command  
      * @param rc  
      * @throws IOException  
      */   
     private void sendCommand(String command,int rc)throws IOException{   
         // format the command sent to server   
            
         command += CRLF ;      
         System.out.print(command);   
         toServer.writeBytes(command);   
            
        /*get the reply*/   
         String reply = fromServer.readLine();   
         int code = parseReply(reply);   
         if(code == rc){   
             return ;   
         }   
         else    
             throw new IOException(command);   
                
         /*  
             DATA  354   
             HELO  250   
             MAIL FROM  250   
             QUIT  221   
             RCPT TO  250   
   
          */   
            
     }   
     /**  
      * parse the reply from the server return the reply code   
      * @param reply  
     * @return  
      */   
     private int parseReply(String reply){   
         StringTokenizer tokens = new StringTokenizer(reply);   
         int code = 0;   
        try{   
             code = Integer.parseInt(tokens.nextToken());   
         }   
         catch(Exception e){   
             code = -1;   
         }   
         return code;   
     }   
     /**  
      * destructor.closes the connection if fail  
      */   
     protected void finalize()throws Throwable{   
         close();   
     }   
        

}

You have the main method in the MailClient.java. The only way I know to get that error is if you accidentally try to run a class with no main, so I would say try it again and make sure you run the MailClient class.

tried re-tuning the code, and i still receive the error, dont know if it will help but heres the exact print out i recieve

Exception in thread "main" java.lang.NoClassDefFoundError:
Caused by: java.lang.ClassNotFoundException:
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: . Program will exit.

Mattox is right. It's probably a problem in your run configuration. In particular check that your "main class" is MailClient in the run configurations dialog.

see if ... its just eclipse being a pain

The usual way that Eclipse is a "pain" is because it insists on helping you to have an error-free program and configuration. The chances of it being an Eclipse error rather than your own are roughly on a par with winning the lottery...

when i go to compile it in eclipse i get an error along the lines of cant find "main" class, program will now terminate

No. You do not get that error trying to compile anything. The distinction between compile-time errors and runtime errors is important.

Edited 5 Years Ago by JamesCherrill: n/a

thanks everyone, this had me incredibly frustrated. you were right my run configuration out of order

This question has already been answered. Start a new discussion instead.