• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Chris, Paul!

Regards,
Flom
 
They weren't very bright, but they were very, very big. Ad contrast:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic