 |
BOOK: Beginning Cryptography with Java  | This is the forum to discuss the Wrox book Beginning Cryptography with Java by David Hook; ISBN: 9780764596339 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning Cryptography with Java section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 24th, 2006, 01:18 PM
|
|
Registered User
|
|
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
NoClassDefFoundError: javax/mail/MessagingExceptio
I've been trying to run the SMIME examples in Chapter 9 and keep getting NoClassDefFoundError: javax/mail/MessagingException.
I'm running with JDK1.5 build 1.5.0_04-b05.
When I run EnvelopedMailExample I get:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
at chapter9.EnvelopedMailExample.main(EnvelopedMailEx ample.java:38)
I've tried running the examples in Eclipse 1.3 as well as from the command line and I get the same thing.
Here's the command line that I'm using (bin has all the classes for chapter1-9):
java -classpath bin;c:\javamail-1.3.3_01\mail.jar;c:\jaf-1.0.2\activation.jar;c:\bouncycastle\bcmail-jdk15-131.jar;c:\bouncycastle\bcprov-jdk15-131.jar" chapter9/EnvelopedMailExample
I've checked mail.jar and javax.mail.MessagingException is in there...
What am I missing here?
Any help would be appreciated!
|
|

March 24th, 2006, 07:33 PM
|
|
Wrox Author
|
|
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
|
|
This should work, at least from the command line. You might have problems with eclipse if the provider isn't in jre/lib/ext.
Normally this means that the class is appearing twice in your classpath - it would be worth checking the jre/lib/ext area of your JVM to make sure the jar isn't in there as well.
Regards,
David
|
|

March 27th, 2006, 12:25 PM
|
|
Registered User
|
|
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The bcmail and bcprov jars were already added to lib\ext so I removed them from the command line - but problem still not solved...
I added code (at the beginning of main()) to construct an instance of javax.mail.MessagingException and then print out the class name and message. No exceptions are encountered until the line where the generator is constructed.
java -classpath "c:\javamail-1.3.2\mail.jar;c:\jaf-1.0.2\activation.jar;bin" chapter9/EnvelopedMailExample
javax.mail.MessagingException mymessage
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
at chapter9.EnvelopedMailExample.main(EnvelopedMailEx ample.java:43)
Line 43 is: SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
Why would I be able to instantiate the MessagingException class in my main(), but then not be able to find the class from within the SMIMEEnvelopeGenerator() constructor?
|
|

March 27th, 2006, 07:09 PM
|
|
Wrox Author
|
|
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
|
|
Actually this will make the problem worse - you have a different class loader loading the BC mail API from the java mail API and the first class loader won't talk to the second one. Try adding the javamail and activation jars to lib/ext as well.
Regards,
David
|
|

March 28th, 2006, 02:52 PM
|
|
Registered User
|
|
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks David,
It all works from the command line now, but when I run under Eclipse I get the following exception:
Exception in thread "main" java.security.NoSuchProviderException: JCE cannot authenticate the provider BC
at javax.crypto.SunJCE_b.a(DashoA12275)
at javax.crypto.KeyGenerator.getInstance(DashoA12275)
at org.bouncycastle.mail.smime.SMIMEEnvelopedGenerato r.make(Unknown Source)
at org.bouncycastle.mail.smime.SMIMEEnvelopedGenerato r.generate(Unknown Source)
at chapter9.EnvelopedMailExample.main(EnvelopedMailEx ample.java:57)
Caused by: java.util.jar.JarException: Class is on the bootclasspath
at javax.crypto.SunJCE_d.a(DashoA12275)
at javax.crypto.SunJCE_b.b(DashoA12275)
at javax.crypto.SunJCE_b.a(DashoA12275)
... 5 more
Why would the provider be authenticated from command line, but not from within Eclipse?
I have bcmail and bcprov and mail and activation jars in JDK\jre\lib\ext
I have the following line added to the java.security file of JDK\jre :
security.provider.7=org.bouncycastle.jce.provider. BouncyCastleProvider
I have made sure that the JRE system library in Eclipse includes the bcmail, bcprov, mail and activation jars.
I also have the unrestricted policy jars copied to my JDK\jre\lib\security directory.
|
|

March 29th, 2006, 01:40 AM
|
|
Wrox Author
|
|
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
|
|
It's a class loader issue again, not related to the policy files. Normally you'll get this if eclipse is trying to load the provider as a separate jar rather than using the one in jre/lib/ext.
Regards,
David
|
|

May 28th, 2006, 07:27 PM
|
|
Registered User
|
|
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi. I have a similar problem. I am using NetBeans 4.0 with JDK 1.5.0_06. I have an application that sends messages using Javamail. It works fine with the IDE but when I want to run the .jar from command line I get
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
at inicio.Main.main(Main.java:24)
I have copied mail.jar and activation.jar in jre/lib/ext and /lib.
1. How can I specify the classpath using the the -jar option (Since I want to run a jar, not a class)?
2. How would I modify the manifest to "tell" the jar where to look?
Thanks in advance.
|
|

May 28th, 2006, 08:07 PM
|
|
Wrox Author
|
|
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
|
|
You can find details on 1 and 2 in the documentation for the java tool and the documentation on jar files that comes with the JDK.
With the missing class, the most common reason for this, if you're using windows, is that the command line uses the JRE install not the JDK install. If you are using windows you should check that lib/ext of the JRE install also contains the jar file.
The other reason this can happen is if the jar has somehow being included twice in the classpath.
Regards,
David
|
|
 |