Search code examples
javamavenactivejdbcjavalite

Can I put different parts of a Javalite project in separate Maven repos?


In my Javalite project, I have my models, controllers, config files and other classes. I want to reuse some of the parts in this project since in my other Javalite projects, I want to use the same models but I don't want to simply copy-paste or rewrite my model classes. Is it possible to put my model classes in a Maven repo, and simply import that repo whenever I want to use the models in any of my Javalite projects? I also want to reuse some of my controllers, so I'm also asking the same thing for the controllers too.


Solution

  • JavaLite projects are Maven modules, and as such, you can create a more complex Maven project with sub-modules that depend on one another. In fact, almost every JavaLite project I build is broken down like that. Here is how we structure modules:

    root module
      |
      +-- common
      |
      +-- web-customer-ui
      |
      +-- web-internal-admin
      |
      +-- web-rest-api
      |
      +-- another_module
    

    Typically, all these modules will want to access the same database, so the ActiveJDBC models are placed into common. The common will also host common services and other util classes shared by other apps (you know.. common stuff :)).

    Then, there are web apps - these are ActiveWeb projects with their respective controllers, views, etc. Each of the web apps depends on common and will use the same services and models.

    We do not share controllers across different web apps, even of their names and features are the same.

    I hope it helps