aspose file tools*
The moose likes Java in General and the fly likes Jar Hell Resolution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Jar Hell Resolution" Watch "Jar Hell Resolution" New topic
Author

Jar Hell Resolution

Kabron Kline
Greenhorn

Joined: Aug 07, 2009
Posts: 20
I have a common project which is imported into other "parent" projects as a JAR file dependency to provide common functionality. My common project has a JAR dependency that is the same JAR dependency for the parent project except that the JARs are different versions.

This is where I'm having problems, one project requires a different JAR file than the project it is being included in. In this situation, I can never be sure which class will be loaded at run time. Thus, my common project is subject to failure since it will use the wrong class version from the dependency jar in the parent project. In reality, I need the common project to use the classes from the dependency JAR version it relies on.

I'm wondering what I can do to resolve this situation. Right now, the JAR dependencies for the common project are not included in the JAR file which it is packaged into. How can I facilitate this without running into problems at run time?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
What does it mean if "one project uses another"? Apparently it means that all classes for both projects are in the classpath at the same time - so the projects are not really separated. What prevents you from using the same jar version in all related projects?

On a more fundamemental level, that's an issue that OSGi solves very effectively. Keeping jar dependencies apart is one of its core functionalities.


Ping & DNS - my free Android networking tools app
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Ideally, fix the underlying issue.

Things like jarjar can create a shadow API, which is an ugly, but workable, solution.
Kabron Kline
Greenhorn

Joined: Aug 07, 2009
Posts: 20
Thanks for the great info guys, much appreciated.

"What does it mean if "one project uses another"?"

What I mean is that the common project is built into JAR (note that this JAR doesn't contain the dependency JARs of the common project), which is then included into other projects for use. Problem is, the commons project requires a different version than what the parent project requires.

"Things like jarjar can create a shadow API, which is an ugly, but workable, solution. "

After doing some preliminary research, I'm unable to determine the performance impact of this solution. Since more classes are loaded, my assumption is that the memory front print would result in increased start up time for applications utilizing the JAR. Does this assumption sound correct? Also, do you know of any other potential performance impacts of using a jarjar JAR?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
The number of classes, and the performance issues those may cause during load time, are very likely to have a miniscule impact. What makes you think that they may have a noticeable impact?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39387
    
  28
And welcome to the Ranch
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Kabron Kline wrote:After doing some preliminary research, I'm unable to determine the performance impact of this solution.
That because there really isn't any.

I'd still have to recommend fixing the underlying issue, though, rather than jumping through hoops to fix it poorly.
Kabron Kline
Greenhorn

Joined: Aug 07, 2009
Posts: 20
"What makes you think that they may have a noticeable impact?"

Forgive my ignorance, a simple JUnit test answered my performance questions. I have not observed any performance impacts using jarjar.

"I'd still have to recommend fixing the underlying issue, though, rather than jumping through hoops to fix it poorly. "

I completely agree with you on this; however, I am in a situation where that may not be an option due to business constraints (i.e. time and money). Thanks for all the great replies!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jar Hell Resolution