users@glassfish.java.net

Re: LinkageError with javax.mail.jar

From: Oliver Verlinden <oliver_at_wps-verlinden.de>
Date: Thu, 19 Sep 2013 20:33:02 +0200

Am Thursday, 19. September 2013, 17:42:12 schrieb Oliver Verlinden:
> 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

Hi,

the issue could have been solved by just providing the required jar files
within the war file and add a sun-web.xml file in the WEB-INF folder with the
following content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application
Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-
web-app_2_5-0.dtd">
<sun-web-app error-url="">
    <class-loader delegate="false"/>
</sun-web-app>

With this configuration I can instruct the glassfish classloader to prefer the
jar files provided with the application instead of use the included module jar
files.

Best regards
Oliver