users@glassfish.java.net

LinkageError with javax.mail.jar

From: Oliver Verlinden <oliver_at_wps-verlinden.de>
Date: Thu, 19 Sep 2013 17:42:12 +0200

Hi,

I plan to use the Javamail Crypto package to encrypt & sign outgoing messages
(PGP) sent by an Java EE application running on my glassfish application
server.
The javamail crypto api can be found here:
https://sourceforge.net/projects/javamail-crypto/

1) When I add all required jar libraries (cryptix-jce-provider.jar, cryptix-
pki-api.jar, javax.mail.jar, cryptix-message-api.jar, javamail-
crypto-060622.jar, cryptix-openpgp-provider.jar, javamail-crypto-cryptix-
openpgp_060622.jar) in a library folder in the project, glassfish seems not to
find them and throws an NoSuchProviderException during the EncryptioUtils
initialisation:

EncryptionUtils pgpUtils =
EncryptionManager.getEncryptionUtils(EncryptionManager.PGP);

2) When I add these jar files in the glassfish/lib/ext folder, the
EncryptionManager could find the libraries and my keyfiles could be found too.
But this time the glassfish application server fails during execution of the
following line:

MimeMessage decryptedMsg = cryptoUtils.decryptMessage(session, message,
privateKey);

This is the functions which is responsible to encrypt an ancrypted
MimeMessage. In this case I receive an LinkageException for
javax/mail/internet/MimeMessage. I think the problem occurs because glassfish
already contains a javax.mail.jar in the module folder which conflicts with the
javamail package stored in the /lib/ext folder.

Just removing the second javamail jar archive from the /lib/ext folder does
not help. In this case the situation 1 occurs again: The
NoSuchProviderException is thrown because the framework seems not to find the
module jar file.

How can I solve this issue?
I think removing the javax.mail.jar fild from the glassfish modules folder is
not a suitable solution (other applications on the server use this library
too).
How can I manage the coexistance of these two javamail files? How can I tell
the javamail crypto library to find the embedded javamail package instead of
searching the jar file in the external classpath?

Best regards
Oliver