java -cp email.jar Main without .java -- __________________________________________________________________
Jorge Vila Forcén Networked Vehicles Division Mail: [email protected] TELEFONICA I+D Emilio Vargas, 6 28043 Madrid (SPAIN) Tel: +34 91 337 2614 __________________________________________________________________ ________________________________________ De: Alfred Sawaya [[email protected]] Enviado el: viernes, 19 de junio de 2009 13:39 Para: [email protected] Asunto: Error while executing code with SimpleEmail class 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("[email protected]", "foo bar"); email.setFrom("[email protected]", "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: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
