• Post Reply Bookmark Topic Watch Topic
  • New Topic

2 Files with the same Name in JAR - which wins?  RSS feed

 
Flom Xanther
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I have a question:

We have 2 JAR-Files, say:
- a.jar
- z.jar

they contain the same structure and files with the same filenames BUT with different content.

Which of the JARs will win? Which Files will be used?

Thanks a lot!

Regards,
Flom
 
Chris Beckey
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm assuming your talking about which resource (class, properties, etc...) will get loaded?
1.) They may be loaded by different class loaders, in which case it is usually the highest ancestor class loader that wins. Unless the jars gets loaded as part of a webapp (in servlet 2.4 spec and above) then, usually, it is the webapp classloader.
2.) If it is the same classloader then I don't believe there to be a specified behavior. OTOH, if the files are listed in an environment or command line classpath I've yet to see a case where they are not loaded in the listed order.

Where are the jars? a webapp, on the classpath, in lib/ext, in an ear file, referred to in a manifest, etc ...?
 
Flom Xanther
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,

the files are in the "lib"-folder of a webapp.
I have to know, if it is predictable, how the resource are getting loaded.

Thanks,
Flom
 
Paul Clapham
Sheriff
Posts: 22526
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's what the servlet specification (version 2.3) says:
The web application classloader must load classes from the WEB-INF/classes directory first, and then from library JARs in the WEB-INF/lib directory.
That's all it says. So I would say it's not predictable.
 
Chris Beckey
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree that it will not be predicatable. It may work consistently as long as no changes to the environment are made but the behavior could change with peripheral modifications (i.e. seemingly unrelated changes). This could include simple things like copying files or small code changes that affect the order of loading. Note that I'm kinda' taking an educated guess (knowing something about how class loaders work and making some assumptions about how specific instances would be written).
If you are working with an open source web/app server then you could look at its class loaders. They are not tremendously complex themselves (though complexity can arise from the relationships between many of them).
If the order is important then look at the classloader relationships of the web/app server and it should be possible to coax it into the desired behavior. Doing so is probably the most reliable suggestion if the jar files can't be changed.
 
Flom Xanther
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Chris, Paul!

Regards,
Flom
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!