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/Add开发者_如何转开发ress
Why can it find classes when compiling and cannot do it when running? How to correctly run my app?
Thanks in advance
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.
精彩评论