0

I am working on externalizing Resource adapter rars.

Earlier, the rar were packaged inside the /lib of war and everything worked good. Now to make the war light and also generic, I want to externalize resource adapter.

What I have done yet

Removed rars from war 
installed rar externally through WAS7.0 Admin console
configured J2C connection factories for each RAR 

I did a clean ,restart and I got some ClassNotFoundErrors.

Why were these errors there : Basically the rars use some jars that are present inside /lib. so earlier there was no problem but now when I externalized it, I started getting CNFE`s.

How I resolved: When we install a rar through WAS admin console , there is an option to provide classpath. I provided the jars that were causing issues on classpath there. And I could deploy and start my application

The problem:

When I login to my application. There is a line of code in one of the jars (that was causing issues and was added to classpath of resource adapter , note that currently this is present inside war and also on classpath of resource adapter), that is doing a type cast. Now on this statement

I get an exception

java.lang.ClassCastException: com.csc.fs.ra.SimpleMappedRecord incompatible with com.csc.fs.ra.SimpleMappedRecord

I dug up and found that a possible cause is multiple version of same jars. which is a case in my case. i have a version of jar inside war library and also on classpath of resource adapter.

I am kind of out of ideas here. what to do to resolve this kind of situation. please help

Regards

Mukul Goel
  • 8,387
  • 6
  • 37
  • 77

2 Answers2

0

You can check the classloaders. It will show you all jars that are loaded.

Udo Held
  • 12,314
  • 11
  • 67
  • 93
0

The RAR and the WAR got their own ClassLoader, even if you use the same version of the jar, each one of them loads the class separately and you get ClassCastException.

Before when it was embedded it worked because the RAR was using the same ClassLoader.

If the RAR are now separate I think you will have to put the jars in a shared library so it will be loaded by a single ClassLoader.

Aviram Segal
  • 10,962
  • 3
  • 39
  • 52
  • Hmmm.. Yea right. so , what you are saying is I remove the jars from war as well as from classpath of RAR and create a shared library and have war and rar access that? I know how to link a war to a library? . but how do we link a rar to shared library? – Mukul Goel Oct 10 '12 at 07:37
  • One way is to create a shared library at the server scope (You add a shared lib, create a new classloader under the server and add the shared lib to it). If your RAR was in an EAR (even if different than the one the WAR in) you could create a shared library, associate it to both application and it will probably work. – Aviram Segal Oct 10 '12 at 07:47
  • iS it possible to leave the EAR and WAR as they are and configure external resource adapter such that they dont conflict with other application? I mean something like define a different classloader for RAR? – Mukul Goel Oct 10 '12 at 11:10
  • I think RAR does have its own classloader which consist your jar and the classpath you add for it at deployment time. I think I don't understand the question. – Aviram Segal Oct 10 '12 at 12:32
  • probably not, Sorry for not being clear. What I actually meant was. i have a WAR and EAR that contains the libraries. And RAR that require some of those libraries. Now is there a way that I dont modify the WAR and EAR structure (have it have its libraries) and someway give RAR those libraries and there be no class conflicts.. :D – Mukul Goel Oct 10 '12 at 13:25
  • Sorry i'm coming and going because i'm doing more things. there is no way to do that because the EAR/WAR got their own classloaders and the RAR can't that classloader, you can only put all the classes in a higher classloader (higher in the hierarchy) that they both can access – Aviram Segal Oct 10 '12 at 13:28
  • Aviram, I tried it. I removed the three JARS from WAR, EAR and RAR classpath. made a shared Library and associated it to EAR and RAR. but still i keep getting the same classCast exception.. any views? – Mukul Goel Oct 11 '12 at 10:15
  • A question.. can a jar inside a shared library access another jar inside same shared library? – Mukul Goel Oct 11 '12 at 10:48
  • Accepting the answer as it explains about classloader. And suggested the approach of "shared library" which is the way to go – Mukul Goel Oct 26 '12 at 07:28