Package Name - Java EE Web Application

I am starting to program web applications with Java EE. What do you call your packages?

I often saw things like com.abc.commons ... is there a standard or general way to do this?


Thanks seanizer, I will use your approach: com.mycompany.myproject.api

+4
source share
3 answers

These parts are usually included in my package names.

  • Domain name (your or your company / client) back
  • the name of the project
  • 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 different for a single project (jar, etc.). For example: in jar myproject-api.jar, the root package would be com.mycompany.myproject.api . That way, you always know where to find your classes.

+7
source

Yes, see Sun's Naming Conventions .

The unique package name prefix is ​​always written in lowercase ASCII letters and must be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of two English languages ​​defined by countries specified in ISO 3166 , 1981.

Subsequent components of a package name are distinguished by their own internal organization naming conventions. Such conventions may indicate that some components of a directory name are divisions, departments, projects, machines, or logins.

Examples:

  • com.sun.eng
  • com.apple.quicktime.v2
  • edu.cmu.cs.bovik.cheese
+2
source

The usual way is to make your own domain back, as this is a pretty good guarantee that others do not accidentally use these package names.

0
source

Source: https://habr.com/ru/post/1315626/


All Articles