• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Custom order when loading jar files

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I have two jar files, A and B. A is a component, B is a component too, but has some classes that have the same name as some classes in class A. The classes in component B are exptected to override the behaviour of classes in component A. Is there some way to instruct java to give priority to classes in component B when names overlap ?

Thanks
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The classes in component B are exptected to override the behaviour of classes in component A


That sound ugly. Can you explain why they do this?

Overriding methods is easy to do in Java, and doesn't require fixing the load order of classes. Also names in Java should never overlap if you properly package your class files (unless you have more than one version of a class).
[ February 02, 2005: Message edited by: Paul Sturrock ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know, per default Java searches for classes in jar files in exactly the sequence they appear in the class path. That is, if you put the jar file for B before the jar file for A in the classpath, it possibly already works. I'm not fully sure about it, though.

Nevertheless, Paul is right that it sounds ugly. It's probably even the way to hell.

Can you explain why you need to do this?
[ February 02, 2005: Message edited by: Ilja Preuss ]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't sound ugly to me.

There are plenty cases where you want to override badly written code (Like Hibernate using the wrong context to load resources).

When you package your application (including your "a.jar" and "b.jar" files) either in a jar, war or ear file, add /META-INF/MANIFEST.MF (that is directory+file) to your jar, war or ear.

The /META-INF/MANIFEST.MF file has to contain the following:

Manifest-Version: 1.0
Class-Path: b.jar a.jar

Be careful with upper/lower case.
If "b.jar" is declared before "a.jar", the "b.jar" classes will override the "a.jar" classes with the same fully qualified name.

Cheers
[ February 09, 2005: Message edited by: shochan vanden ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic