Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package Name - Java EE Web Application

I'm a beginner in programming web apps with Java EE. How do you name your packages?

I 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

like image 238
Sven Avatar asked Jan 22 '23 18:01

Sven


2 Answers

These parts usually enter into my package names

  1. Domain name (your's or your company's / customer's) backwards
  2. Project name
  3. Artifact name (api, client, test etc.)
  4. 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.

like image 172
Sean Patrick Floyd Avatar answered Jan 29 '23 16:01

Sean Patrick Floyd


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
like image 25
Péter Török Avatar answered Jan 29 '23 14:01

Péter Török