Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jar Hell Resolution

 
Kabron Kline
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ideally, fix the underlying issue.

Things like jarjar can create a shadow API, which is an ugly, but workable, solution.
 
Kabron Kline
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic