We have some common code laid out in packages as expected.
Some of these packages are
handler, processor, util, registration
etc
Common here means these will be re-used across multiple Java / Java EE projects which are unrelated to each other.
The question is on packaging开发者_高级运维 for distribution.
Each package comprises a different functional units but put together, they are an API.
Should we bundle individual functionalities into a JAR and end up with say 8 - 10 jars. eg: handler jar, registration jar etc
or
Should we take the least common denominator approach which is a Base Build of 5 compulsory packages into a single jar. Any one else needs that jar as the base and can choose add-on jars.
Our build system is Ant + Ivy and these dependencies will be resolved at compile and build time.
Unless you have lots and lots of API classes (think Spring) or aware of some interference among them, it is my opinion, that there is very little reason to break them into separate jars. The only other reason to break API in separate jars is to enable different teams work independently.
Managing single jar simplifies a lot of things and it does not worth fixing the problem that does not exist.
Solutions with separate jars is better. BTW if you are using maven and each logical component has its own pom.xml this is the only option.
One big jar has advantage of easier distribution. If for example your users download jar from internet and install them manually it is easier to deal with one jar than with many. But if this is not the case I'd recommend you to use multi-jar solution. But do not forget to stamp each jar with its version. At least put version to the manifest.mf file. Maven also puts version as a part of jar name. This is very good practice.
If api is huge better split into mulitple jars otherwise create multiple jars
Benefits of Single jar If any application wants to use more than one jar eg registration as well as util. he/she have to include only 1 jar.
Limitation If your jar size is very big in and you are using only util classes in the jar then. It may increase application size if size of application is not a problem for you then you can avoid it.
精彩评论