views:

40

answers:

2

Hi guys,

Is it possible to have a Seam project just for entities (src/main) and other projects access them ?

I have a situation that a organization has 6 projects accessing the same entities and i don't want to replicate them in each project. If it is possible, how can i do that ? where can i found documentation about it ?

thanks,

Cateno Viglio

+1  A: 

Yes, it is very common way. Look at Richfaces photo album example where you have ejb module holding domain and used as dependency in web module. Of course you must remember adding empty file seam.properties to result jar file.

PS. This example is built by maven and uses ejb (entities and sessions beans). You can use seam-gen and POJO instead if you like.

cetnar
A: 

Depends on what exactly you mean.

Yes, you can declare separate projects for your entity classes. I have about 50 projects roughly. Of those less than a handful are actually web applications packaged as WAR files. The rest are comprised up of utility projects, service projects, listeners, entities, and servlet filters.

Breaking the projects up this way has its advantages and disadvantages. Any time you make a change to a project, you have to propagate that change throughout the other projects. However, it isolates your code and allows you to write unit tests more easily as you can now focus on 5 classes instead of 500.

Another potential downside is, unfortunately PMD won't be able to detect if you duplicated code between your projects. At least I don't know how to do that yet.

I use this pattern (divide and conquer / refactor out replication) quite a bit to avoid duplicate code.

Walter