commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alfred Sawaya <alf...@reseau2000.net>
Subject Error while executing code with SimpleEmail class
Date Fri, 19 Jun 2009 11:39:35 GMT
Hello world !

I'm trying to use the SimpleMail class but I don't manage to send my mail.
I'm not experienced in Java, and I think it's about how I include the
jar file to my program.

So, this is the source :

    import org.apache.commons.mail.SimpleEmail;
    public class Main
    {
         public static void main(String args[])
         {
             try
             {
                SimpleEmail email = new SimpleEmail();
                email.setDebug(true);
                email.setHostName("smtp.myhost.com");
                email.addTo("foo@bar.com", "foo bar");
                email.setFrom("john@doe.com", "john doe");
                email.setSubject("Test message");
                email.setMsg("This is a simple test of commons-email");
                email.send();
            }
            catch(Exception e) { e.printStackTrace(); }
            System.out.println("ok");
        }
    }

The JAR file downloaded from the apache commons website is in the same
directory of Main.java and is name email.jar .
I compile this way : javac -cp email.jar Main.java
No error, I execute : java Main.java
I have this error :

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

Same error if I try : java -cp email.jar Main

Where do I do wrong ?

Thanks folk !

-- 


  --
|
     .:: Alfred Sawaya ::.
                             |
                           --

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message