Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > BOOK: Beginning Cryptography with Java
|
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
 
Old March 24th, 2006, 01:18 PM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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!


 
Old March 24th, 2006, 07:33 PM
dgh dgh is offline
Wrox Author
 
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
Default

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

 
Old March 27th, 2006, 12:25 PM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?


 
Old March 27th, 2006, 07:09 PM
dgh dgh is offline
Wrox Author
 
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
Default

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

 
Old March 28th, 2006, 02:52 PM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.



 
Old March 29th, 2006, 01:40 AM
dgh dgh is offline
Wrox Author
 
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
Default

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

 
Old May 28th, 2006, 07:27 PM
Registered User
 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old May 28th, 2006, 08:07 PM
dgh dgh is offline
Wrox Author
 
Join Date: Aug 2005
Posts: 206
Thanks: 0
Thanked 20 Times in 20 Posts
Default

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with JAXP (NoClassDefFoundError) Satyajit Sahu XSLT 1 July 13th, 2007 03:53 AM
javax.mail.SendFailedException ramanadyv J2EE 3 May 3rd, 2007 07:54 AM
NoClassDefFoundError Crava J2EE 3 January 30th, 2004 12:48 PM
Java NoClassDefFoundError wireblock JSP Basics 1 August 19th, 2003 01:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.