Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > BOOK: Beginning Cryptography with Java
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 24th, 2006, 12:18 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
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!


Reply With Quote
  #2 (permalink)  
Old March 24th, 2006, 06:33 PM
dgh dgh is offline
Wrox Author
Points: 843, Level: 11
Points: 843, Level: 11 Points: 843, Level: 11 Points: 843, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: , , .
Posts: 203
Thanks: 0
Thanked 19 Times in 19 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

Reply With Quote
  #3 (permalink)  
Old March 27th, 2006, 11:25 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
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?


Reply With Quote
  #4 (permalink)  
Old March 27th, 2006, 06:09 PM
dgh dgh is offline
Wrox Author
Points: 843, Level: 11
Points: 843, Level: 11 Points: 843, Level: 11 Points: 843, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: , , .
Posts: 203
Thanks: 0
Thanked 19 Times in 19 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

Reply With Quote
  #5 (permalink)  
Old March 28th, 2006, 01:52 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
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.



Reply With Quote
  #6 (permalink)  
Old March 29th, 2006, 12:40 AM
dgh dgh is offline
Wrox Author
Points: 843, Level: 11
Points: 843, Level: 11 Points: 843, Level: 11 Points: 843, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: , , .
Posts: 203
Thanks: 0
Thanked 19 Times in 19 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

Reply With Quote
  #7 (permalink)  
Old May 28th, 2006, 07:27 PM
Registered User
 
Join Date: May 2006
Location: , , .
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.

Reply With Quote
  #8 (permalink)  
Old May 28th, 2006, 08:07 PM
dgh dgh is offline
Wrox Author
Points: 843, Level: 11
Points: 843, Level: 11 Points: 843, Level: 11 Points: 843, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: , , .
Posts: 203
Thanks: 0
Thanked 19 Times in 19 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

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 11:48 AM
Java NoClassDefFoundError wireblock JSP Basics 1 August 19th, 2003 01:22 AM



All times are GMT -4. The time now is 10:38 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.