Tip:
Highlight text to annotate it
X
Hi, this Tim Smith and this another video in the "10 Minute Expert" series.
Today I'm going to talk with you about how to resolve conflicts
in jar files when you're doing Java development work inside Informatica.
Now whether you're developing
Java code inside the Java transformation in
PowerCenter, data services or data quality...
The way that gets executed is inside the environment there's a
Java Virtual Machine or JVM.
And inside of it is a classloader. When you request
a class, the class loader is responsible for finding
it and it looks down the classpath. It looks in jar files and in class files.
These files are organized not just
within jar files to group them together but also
in package names in this example you see a job a transformation that's importing
from the package
org.example. When a request is made
to create an object of this type the class loader goes out
and searches the disk for the file that contains that class
and it will load that class. All the definitions
and executable code and allowed it to be executed. This works fine until
you are using different versions.
When you're not able to maintain compatibility. For example,
the method might get deprecated. And another example,
I might have a case where the first example
here we have a findData()
that's being passed a long, now
I a need to pass a string. Because I'm using a new version
of the method and it only expects a string. Well the class loader can go out and
find that as long as you've got the jar file.
And again this works fine.
But what happens if you need to use
the old and the new version of the jar file?
So in that case your first execution might work (or may not depending on
which classes it finds first. But if we find the
classname and that's loaded, and we try to use the
other version then the class loader will get a conflict
with the two different versions. And will not allow
a duplicate class being loaded. And the request will fail.
because you can't find something to fulfil the method signatures
so the core problem is that
job does not like the same class name being loaded twice
arm so their couple of ways you can
met deal with is the first is if you have access to the source code you can
change the source code
for your library's so in this example will change
or sample to work example B-two's
Pakistan guess change in there won't be a conflict anymore there's another
little utility that I found called George or links in this is very useful
when you're using libraries like apache commons or
lot for J or other
library such as that if you're using those libraries and Informatica uses
those libraries
then it's very possible to hit a conflict if one is using a new were
package than the other newer version library
so what George Arliss does is it allows you to change
the packaging
for a package and for example
I can then have a jar file that contains
workday example and my first job transformation work
then my second job from transformation will
import or did not example underscore be too
so I've renamed it to be too in inside the jar file
in my appropriate folder are
have org example: v2 so even though the original class file
referred to org example: this is able to go
into the jar file just rename the
the different class packages
let me give you a quick example quick demonstration
I've created an example to show how this works I have
a class called shared class that's in the package
or that bogus it has two different methods the first is version
and every turns a strain that is the version so v1
the second is say something and say something accepts
two parameters to strings and all it does is can't make those together
I have another java file called share class and this is my second version so
this is my new version
and when I ask for version I should get the two
but now instead hard-wired two strains I now take an array of strings
and these get concatenate together in return and it also has a space in
between
the different parts so to
classes with the same name and Tom
now above that I have a test harness
the test harness is just test one
contest to you both assume different versions of shared classed s1
has run test and you specify
or that is yet it calls the shared class
concatenate *** with
a concatenated string first and second so-called say something
with first and second the second
does the same thing but accepts expects a different method signature
it is passing the string array
now I can't compile these and Ryan test line with this shared class and it's
going to XQ
fine I can run test to do with the share classes going to execute fine
and if thou that's all I need to do inside have
you for Mac I was call one of these then I would be fine as long as
nothing else was referring to the the a different version
but I want to force the failure so that's the way I did that
the I have to Java transformations inside the mapping
in a logical object: and these are
Pauline the two different s you'll see here I'm calling test one
in here I'm calling test to and it takes those values whatever those return and
help but
so I can preview
and the here I'm getting version B one
with the result first and second so those go got cagney
concatenated together now let's call this one
and you'll see a very got the error message there
it says no such method air so it loaded
the class in it went ahead and loaded this
class and now
that it's loaded can't see the other class
the location the jar files is found in the services shared jars third-party
that's where you can add your own jar files
and I have compiled those four different files into four different jars
and those are the B-one B-two test harness the want src to you
so we have a conflict with the B-one and B-two you that we need to resolve
the whale resolve that is by combining
the test harness the two with might be to GR
and then changing the contents of that so that the package is different for the
BT joke
you can see what is inside the jar
what the packages are by
ok using jar
and see have got or bogus share class there
and the inside my test harness the two
I have worked as hard as test to
so I'm going to change and want to combine these two together
into one jar file and then I'm going to you
change or bogus to another
path or another package let's go ahead and get ready have
v2 jar
in the test harness the two
and I'll copy the the to you acts dot jar so
the v2 axe
I have renamed or bogus to be
organics or bogus so I've added another layer on top a bit
the test to class was inside the same folder
and that when I win I
ran the the utility on this JAR file yet
change the test to class to look at
this path instead of the previous path for package
so everything's combined together now got one
jar file that has everything that I need I should be able
have done something very wrong should now be able to preview this
and you'll see that my version one is working
and my version two is working be
note that the first and second has a space in between and BTU
got return now how did it work
how does this magic work going to you show you a
batch file that I created and
in this what I'm doing is I compiled the various
files the shared class is compiled
the test harness version 1 /version to you
are compiled and they are then jarred so I jar to b1 b2
night src want SRC to use the class files each going their own separate
files
then I test to make sure that my test harness is working
I XQ test1 test2 and that does
now they're that that got me too those four jar files that I started out with
when I'm show you
now and going to combine
the jar files for the *** to so the test harness version to you and Tess
harsh version 1 the way that I do that
is I have a folder called combine and I
extract all the information and v2 Jr
in the test car sweetie jar and I combine it all back together
into you a temporary
file called pre test harness the 2x
and %ah the final stab
is to you run the Jar Jar to
so under the tools folder I have the Jar Jar
application this execute it I say process
in roles that txt which tells it how to manipulate the
jar file I give it my pre filed
input file and the output file
there's my test times the 2x jar
last step is to copy the file which I didn't wanna do you
indiscriminately so I've got this comment
next thing I want to show you is what the input here
the input rules for charger and lynx is
that is this last file very simple I said
here's the rule I want you look for anything that's in the
org not bogus and I want you to prefix it
with organics that's it
so Jar Jar links reads this text file
executes the all the rules that you can specify there and there's different
types of roles you can create but I only need a simple
your and yet takes the input jar
writes the output jar with modifications
so finally weekend look one more time
and I can say jar he have
you will like it the free
so that's before
and that's after so before everything was under
or bogus now it's under organics were bogus
and that's the way it works some final notes for you
this is this will not work the example using charger links will not work yes
classes are being mainly loaded
the classloader so if that is the case
there's a static string bean used and charger links does not
identify or do anything with that you might be able to use a class file
editor I've seen some out there I didn't need to do that so I haven't tried it
I'm I imagine it would work by that's up to you to you
experiment with that the URL for the judge Orleans
project is on the Google Code site
and if you have any questions about this feel free to post questions from
to the Informatica community by I remember I didn't write this so
I don't support it if you
arm are having problems P please post to the site
I may be able to respond others might respond but
as a community if everyone contributes then
we all benefit from that
and I'll last night lease please let me know if you found this
recording useful the 10 min expert series take some time and I
appreciate any feedback so thanks for your time I hope this was helpful
and until next time