aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Packaging JavaMail JARs into Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Packaging JavaMail JARs into Application" Watch "Packaging JavaMail JARs into Application" New topic
Author

Packaging JavaMail JARs into Application

Tomas Anderson
Greenhorn

Joined: Feb 26, 2006
Posts: 16
Hello,

I am developing an application which uses the JavaMail API. I have found JavaMail very easy to use, but, while packaging my application, I have run into a problem. I wish to package my application into a single self-extracting jar file. However, I also want to include the JavaMail jars (mail.jar, activation.jar, etc) in my application so that my clients don't have to put the JavaMail jars into their /lib/ext folders. I have not been able to successfully package my application into one self-extracting jar file without getting a NoClassDefFoundError at runtime.

Could anyone please advise me on how to package the JavaMail jar files into my application? I have done some searching and can only come up with this bug report.

Regards,

TBA
[ May 25, 2006: Message edited by: Tomas Anderson ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42600
    
  65
The bug report sounds to me as if it is about a different problem.

Generally, you should have no problems creating just one jar file out of many. However, you may run into problems if people already have one or more of the jars in their extension directory. You could easily get a version mismatch in that case. Might that be the case here?


Ping & DNS - my free Android networking tools app
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

The simple and straightforward way to do it is this:

1. Put a line in your jar's manifest that looks like this:2. Install your jar file, mail.jar, and activation.jar in the same directory.
Tomas Anderson
Greenhorn

Joined: Feb 26, 2006
Posts: 16
Class-Path: mail.jar activation.jar


That looks very helpful; would it add to the classpath or overwrite it?


Install your jar file, mail.jar, and activation.jar in the same directory.

Can I put mail.jar and activation.jar inside my jar file?

thanks,
TBA

[EDIT] PS: I highly doubt a version mismatch is the problem. [/EDIT]
[ May 27, 2006: Message edited by: Tomas Anderson ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

Originally posted by Tomas Anderson:
That looks very helpful; would it add to the classpath or overwrite it?

Neither. If you are running your executable jar via "java -jar something.jar" it would BE the classpath, along with the executable jar itself.
Can I put mail.jar and activation.jar inside my jar file?
Not if you expect the manifest's Class-Path entry to be able to find them.
Tomas Anderson
Greenhorn

Joined: Feb 26, 2006
Posts: 16
Thanks for the help.

I was hoping to get my whole program (+mailAPI) into one jar file, but 1 directory should suffice.

Regards,
TBA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Packaging JavaMail JARs into Application