CITBL
CITBL

Reputation: 1677

Compiled OK but NoClassDefFoundError when running

I'm trying to send an email using JavaMail API. I have jdk 1.5 installed in my home directory from self-extracting binary. I'm on Ubintu 9.10

I compile the program using the next command:

~/jdk1.5.0_22/bin/javac -classpath ~/jdk1.5.0_22/jre/lib/javamail-1.4.3/mail.jar:~/jdk1.5.0_22/jre/lib/jaf-1.1.1/activation.jar hw.java

It compiles OK. As you can see I have specified the path to mail.jar and activation.jar Now I try to run the app using the next command:

~/jdk1.5.0_22/bin/java -classpath ~/jdk1.5.0_22/jre/lib/jaf-1.1.1/activation.jar:~/jdk1.5.0_22/jre/lib/javamail-1.4.3/mail.jar:. HelloWorldApp

I get an exception java.lang.NoClassDefFoundError: javax/mail/Address

Why can it find classes when compiling and cannot do it when running? How to correctly run my app?

Thanks in advance

Upvotes: 3

Views: 1059

Answers (1)

Brian Agnew
Brian Agnew

Reputation: 272417

That class should come from your mail.jar. I'm not sure your classpath is being parsed properly. The tilde (~) is a shell function and needs expanding before being sent to the Java process. Have you tried removing the ~ and replacing with /home/{whatever} ? I suspect that's the issue.

Upvotes: 2

Related Questions