i have a very strange(for me) Question. I use bouncy castle to de-/crypt some Mails in a Web Application. I get this Exception after redeployment of my Application
java.lang.NoClassDefFoundError: org/bouncycastle/jcajce/spec/SkeinParameterSpec at org.bouncycastle.jcajce.provider.symmetric.util.BaseMac.engineInit(Unknown Source) at javax.crypto.Mac.init(Mac.java:443) at org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.calculatePbeMac(Unknown Source) at org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.engineLoad(Unknown Source) at java.security.KeyStore.load(KeyStore.java:1445) at my.application.Class.getDecryptedContent(my.application.Class.java:401) at my.application.Class.decrypt(my.application.Class.java:91) at my.application.Class.getKvConnectMail(my.application.Class.java:320) at my.application.Class.processEinClick(my.application.Class.java:198) at my.application.Class.shedule(my.application.Class.java:44) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273) at org.springframework.scheduling.support.MethodInvokingRunnable.run(MethodInvokingRunnable.java:65) at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:51) at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
So i thought the lib is missing in WEB-INF/lib folder of my Application but it is there.
The strange thing is: If i use the Class direct with this Codesnipped the Snipped is executed correct without errors.
LOGGER.error("Class!!!: " + SkeinParameterSpec.class.getName());
SkeinParameterSpec spec = new SkeinParameterSpec();
LOGGER.error("Instance!!!: " + spec.toString());
LOGGER.error("Instanceof: " + (spec instanceof SkeinParameterSpec));
But the Library Class org.bouncycastle.jcajce.provider.symmetric.util.BaseMac which uses near the same code as my snipped ends with the Exception above.
Somebody out there who can help me to understand why this happens?
P.S.: This only happens after a redeployment if restart the whole Tomcat every thinks works.
UPDATE 1: I have forgotten to say that i use Liferay. But my WebApplication is a normal one without any relations to Liferay.
But: After some investigation i found out that Liferay have some librarys (/tomcat/webapps/ROOT/lib). Also Bouncycastle in an old version. Is it possible that this librarys are used by my WebApplication and the error is a result of Liferay's librarys and CustomClassLoaders?
Solution: See 'inigo skimmer' comment at the right answer.
I guess there may be another version of bouncycastle lib on the classpath (may be in Tomcat/lib folder) or required by some other jar that is loaded first and doesn't contain the desired class.