This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?
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.
Things like jarjar can create a shadow API, which is an ugly, but workable, solution.
Joined: Aug 07, 2009
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?
Joined: Mar 22, 2005
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?