Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.lang.NoClassDefFoundError: javax/mail/Session

843830Sep 14 2002 — edited Sep 14 2002
I am working on a Linux machine trying to run a simple application of JavaMail.

I have made a class called JavaMail. It compiles alright. When I run it using simply java MailTest, I get the following error <i> java.lang.NoClassDefFoundError: MailTest</i>

I made a jar file called app.jar. When I run it, the error I am getting is <b>java.lang.NoClassDefFoundError: javax/mail/Session.</b> The code snippet is as follows.

<code>
import javax.mail.internet.*;
import javax.mail.*;
import java.util.*;

public class MailTest
{

public void runIt()
{
try
{
String username = "myUsername";
String password = "myPassword";

System.out.println("Hello and Welcome to my Mail Client");
Properties prop = new Properties();

// The error is on this line
Session session = Session.getDefaultInstance(prop,null);
Store store = session.getStore("pop3");

store.connect("10.10.11.156",username,password);

Folder folder = store.getFolder("INBOX");

folder.open(Folder.READ_ONLY);

Message msg[] = folder.getMessages();

System.out.println(" A Total of "+msg.length+" message");
System.out.println("**********************************");
for (int i=0; i<msg.length; i++)
{
System.out.println("# "+(1+i)+" : "+msg.getFrom()[0]);
System.out.println("Subject : \t"+msg[i].getSubject()+"\n");

}

}
catch(Exception e)
{
System.err.println("Error");
}
catch(Error e)
{
System.out.println("Linkage error: "+e);
}

}


public static void main(String arg[])
{
try{

MailTest m = new MailTest();
m.runIt();
}
catch (Exception e)
{
System.out.println("A Run time Exception has occurred"+e);
}

catch (Throwable e)
{
System.out.println("A fatal exception: "+e);
}

finally { System.out.println("System is shutting down now");
}
}
}


</code>

I am also listing the text of .bash_profile so that you can understand the paths which I setup.

The jdk,j2ee,mailAPI and jaf are all set on my account.
<i>
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

#PATH=$PATH:$HOME/bin
JAVA_HOME=$HOME/jdk
J2EE_HOME=$HOME/j2ee
PATH=$PATH:$HOME/j2ee/bin:$HOME/jdk/bin:$HOME/j2ee/lib:$HOME/javamail:$HOME/javamail/lib:$HOME/jaf:$HOME/jdk/lib
CLASSPATH=$HOME/javamail/mail.jar:$HOME/jaf/activation.jar:$HOME/javamail/lib/pop3.jar:$HOME/j2ee/lib/j2ee.jar
export PATH
export JAVA_HOME
export J2EE_HOME
export CLASSPATH
unset USERNAME
</i>

The classpaths, all seem alright but I can understand what the problem is. Can someone please help me out.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 12 2002
Added on Sep 14 2002
1 comment
995 views