I have two java projects that are fairly independent beside the fact that they share a common mysql database. I wanted to refactor these project and extract everything regarding the common data layer. I am using jOOQ, so most of this layer gets autogenerated in my build. Beside that i then have a few common entity classes that are used in both projects.

what would be the best practice to separate this, so that any change can be done one place and still propagate to both projects? create a third java simple project with the common code? what would you do

有帮助吗?

解决方案

I work on a distributed system, and multiple daemons need access to the same Postgres database via jOOQ. Since each daemon is its own Java project, I am in the same boat as you basically.

The solution I've been using is to create a third Java project as a Java Library. If you're using Netbeans you can just include it as a subproject dependency and any changes to the library project can be recompiled into the individual application projects.

One thing of note, you'll need to specify the jOOQ library jars in all 3 projects. In Netbeans its easy to specify a project's library directory, and have multiple projects share these dependencies. Netbeans will copy the dependencies at deployment time.

Edit:

The steps are basically:

  1. create a master layout for system, IE:
    /master-project/
    /master-project/library
    /master-project/software
    /master-project/software/daemon1
    /master-project/software/daemon2
    /master-project/common
    /master-project/common/utility1
    /master-project/common/utility2
    
  2. create third-party "library" bundles of {jar,src,docs} under /master-project/library.
  3. create "application" projects under /master-project/software, making sure to tell Netbeans to only use third-party libraries under /master-project/library.
  4. create "library" projects under /master-project/common, making sure to tell NB only to use third-party libraries under /master-project/library.
  5. create a "library" for jOOQ code to be shared, as in step 4.

Each project is responsible for its own compile script (including generating jOOQ code, if desirable), and correctly specifying its dependencies out of /master-project/library, and /master-project/common.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top