jar - Java package understanding in real life projects -
i want understand packing methodology in real big projects.
suppose have package com.abc.xyz, , this, have path com/abc/xyz.
is possible have multiple same package names in different directory structure like:
directory path 1: /home/user1/project/module1/src/java/com/abc/xyz
directory path 2:
/home/user1/project/module2/src/java/com/abc/xyz
and when create jar whole project, create jar respect com directory?
when application uses import com.abc.xyz, how know directory path's package referring to?
and finally, there book/resource gives guidelines packaging, how divide project modules, package names etc.
one more thing, project have common package base name in above case: com.abc.xyz (e.g., org.apache.hadoop ).
thanks, vipin
packages created in different source directories same package, far classloader concerned. doesn't matter if class files in same jar or different jars. jvm not discriminate based on source code came from. (of course if have 2 jars loaded different classloaders going treated differently.)
one case have different source trees same package when have tests in different directory (using usual maven convention code under src/main/java , tests in src/test/java) same package code exercise. these tests able exercise protected , package-private parts of code under test, because they're in same package code.
the path of directories inside jar should start @ root of package. (the topmost directory should /, 1 called com or org or whatever, etc.)
organizing code packages done differently different people. people organize code layer (putting controllers in 1 package, services in package, daos in still package), organize code feature.
package-by-layer conventional way of organizing code, seems preferred practice in java community. the java practices website makes interesting case package-by-feature:
package feature package-by-feature uses packages reflect feature set. tries place items related single feature (and feature) single directory/package. results in packages high cohesion , high modularity, , minimal coupling between packages. items work closely placed next each other. aren't spread out on application. it's interesting note that, in cases, deleting feature can reduce single operation - deleting directory. (deletion operations might thought of test maximum modularity: item has maximum modularity if can deleted in single operation.)
here's question asking package feature or layer.
Comments
Post a Comment