You are currently viewing the BOOK: Beginning Cryptography with Java section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
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):
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.
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.
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?
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.
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.
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.
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?
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.