Reputation: 86935
I have a webserver project that works with soap webservices and saves data to db.
Now I'd like to write some importer classes that process build some kind of database cache on a regular basis. These importer classes should reuse lot's of the webserver project (especially the domain leyer, domain POJOs, database services, configs etc). The importers shall later run on a different machine than the webserver, thus independently.
How does a maven/eclipse project have to be structured so that I can separate these two projects, but reuse lots of the common code?
Would I place the classes just both into the same project? Or would I move the common code to a single jar, and create 1 webserver and 1 importer project using this jar as dependency?
Upvotes: 2
Views: 375
Reputation: 40076
Your last paragraph did give a rational solution.
If the importer and web application is something that is closely related, and the "reusability" for those "common class" is aimed to be within this project only, what you can do is having a multi-module project like this:
foo // your project name
+ foo-main // your reusable classes, you may split it into several modules if appropriate
+ foo-web // have foo-main as dependency
+ foo-importer // have foo-main as dependency
+ foo-parent // my personal preference is to make parent project a module, not mandatory
If your importer is something irrelevant to your foo project, but you still want to reuse, you can split it out
foo // your project name
+ foo-main // your reusable classes, you may split it into several modules if appropriate
+ foo-web // have foo-main as dependency
+ foo-parent // my personal preference is to make parent project a module, not mandatory
bar-importer // another project, having foo-main as dependency
or even make that common code a separate project
app-common // the common code in original foo-main,
// maybe a multi-module project
foo // your project name
+ foo-main // foo-specific codes, have app-common as dependency
+ foo-web // have foo-main as dependency
bar-importer // having app-common as dependency
For Eclipse, there should be nothing to worry about. Given you are using latest Eclipse + M2E plugin (should already been bundled with latest Eclipse), if you have correct POM, when you are importing the projects to Eclipse (by Import -> Existing Maven Project), relationships between projects should already been created.
Upvotes: 2