Package Name - Java EE Web Application
I'm a beginner in programming web apps with Java EE. How do you name your packages?
开发者_StackOverflowI often saw stuff like com.abc.commons... is there a standard or a common way to do that?
Thanks to seanizer, I gonna use your approach: com.mycompany.myproject.api
These parts usually enter into my package names
- Domain name (your's or your company's / customer's) backwards
- Project name
- Artifact name (api, client, test etc.)
- Functionality
example:
com.mycompany.myproject.api.services
// contains service interfaces for project myproject
com.mycompany.myproject.common.util.string
// contains string-related utility classes that reside in a library module
// that will be used by several other artifacts
One good practice is to have a common root package that is distinct for an individual project (jar etc). For example: in the jar myproject-api.jar , the root package would be com.mycompany.myproject.api
. That way you always know where to find your classes.
Yes, see the Sun Naming Conventions.
The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981.
Subsequent components of the package name vary according to an organization's own internal naming conventions. Such conventions might specify that certain directory name components be division, department, project, machine, or login names.
Examples:
- com.sun.eng
- com.apple.quicktime.v2
- edu.cmu.cs.bovik.cheese
The customary way is to do your own domain backwards, as this is a pretty good guarantee that others do not accidentially use those package names.
精彩评论