Package structure for a Java project?

What is the best practice for setting up package structures in a Java web application?

How would you install the src code, unit test, etc.?

+85
java packages
Oct. 16 '08 at 22:48
source share
7 answers

You can follow the maven project standard. You do not need to actually use maven, but it will facilitate the transition in the future (if necessary). In addition, other developers will use this layout, since many open source projects are laid out in such a way

+68
Oct 16 '08 at
source share

There are several existing resources you can check:

For what it's worth, my own personal recommendations that I usually use are as follows:

  • Start with a reverse domain, for example. "Com.mycompany".
  • Use a product name, for example. "MyProduct". In some cases, I tend to have generic packages that are not specific to a particular product. They will be classified according to the functionality of these general classes, for example. "io", "util", "ui" etc.
  • After that, he becomes more free. Usually I group according to the project, area of ​​functionality, deployment, etc. For example, I can have "project1", "project2", "ui", "client", etc.

A few other points:

  • This is quite common in projects that I worked on for package names that stem from project documentation. Typically, products are already divided into areas of functionality or purpose.
  • Don't stress too much about immediately pushing the general functionality into higher packages. Wait until you need projects, products, etc., and then a refactor.
  • See dependencies between packages. They are not all bad, but this can mean a tight connection between what can be separate units. There are tools that can help you keep track of this.
+51
Oct 17 '08 at 1:32
source share

I would suggest creating the structure of your package by function, not by implementation level. Good entry on this Java practice: package by function, not layer

+36
Jul 31 '10 at 22:23
source share

Here you can read about standard directory layouts and the directory / package structure for a java project.

+4
Oct 08 2018-11-11T00:
source share

I usually like the following:

  • bin (binaries)
  • doc (Documents)
  • inf (Information)
  • lib (Libraries)
  • res (Resources)
  • src (Source)
  • tst (Test)

This can be considered unconventional, but I believe that this is a very good way to organize things.

+4
Oct 10 '15 at 18:55
source share

Another very good article about Java package structure: Java classpath management

+3
May 10 '13 at 15:47
source share

As usual, I have a folder hierarchy -

  • the name of the project
    • CSI
    • Ben
    • Tests
    • libs
    • documents
+1
Oct 17 '08 at 1:55
source share



All Articles