Javamail demo not working

589 views Asked by At

I have tried running the demo msgsend from JavaMail. I have downloaded version 1.4.5 of JavaMail and unpacked it into my JDK folder. I have added mail.jar to CLASSPATH. I have compiled msgsend.java without getting any error back. However, when I then try running java msgsend I get an "Could not find the main class: msgsend" error.

I am a total noob in Java world and have spend hours browsing through the Internet trying to find an answer but to no avail in my case.

Here is what I get in the console. What am I doing wrong?

C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>echo %CLASSPATH%
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\mail.jar

C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>javac -cp "%classpath%" ms
gsend.java

C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>java msgsend
Exception in thread "main" java.lang.NoClassDefFoundError: msgsend
Caused by: java.lang.ClassNotFoundException: msgsend
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: msgsend.  Program will exit.

C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>java -cp "%classpath%" msg
send
Exception in thread "main" java.lang.NoClassDefFoundError: msgsend
Caused by: java.lang.ClassNotFoundException: msgsend
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: msgsend.  Program will exit.

C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>
2

There are 2 answers

8
David Bejar On

Classes are case sensitive. Be sure you have the compiled MsgSend in your class path, and invoke the compiled class with the proper case.

Try java MsgSend

Edited:

This is how it will work:

Compile as you were doing: javac.exe -cp ..\mail.jar msgsend.java And then to run the compiled class do: java -cp ..\mail.jar;. msgsend In other words: you were missing the current folder in your classpath.

1
Bill Shannon On

You didn't include the directory where msgsend.class exists, usually the current directory ("."). See the examples in README.txt included with JavaMail.