What’s the best way to setup Maven for a project that has a SmartClient architecture? Consider the following packages:
- myproject.core
- myproject.server
- myproject.client
Of course there are several sub-packages in each. Client and Server both use core. I see two main options:
- Make an uber-POM in myproject to cover all three and have some sort of build parameter to identify what to build.
- Make a POM in each package above (one for core, another for server and another for client).
Here are the outputs we need to build (at a minimum):
- Standalone.jar: A test application that will launch the server and a client.
- Server.war: A WAR file that can be deployed to Tomcat.
- Client.jar: The SmartClient without any server code.
Is option #1 even possible? If so, is it good practice? From my initial research, option #2 sounds like best practice. However, jumping from POM to POM when all the code is intimately related sounds like extra work and extra clutter we may not need. Should I just stick with option #2?
Maven has a general rule that there should be only a single artifact per project. In other words, option #1 wouldn’t allow you to produce a server.war, a client.jar, etc without fighting against maven. This would be a big mess and you wouldn’t be able to take advantage of maven plugins. No, really, you don’t want this. So just go for option #2, with a structure like (omitting the
srcdirectory):Regarding your concern about jumping from POM to POM, well, just import all modules into your IDE and you won’t really notice it. This just works pretty well for lots of people.
UPDATE (to cover questions from the OP in comments):
No, and you will loose 🙂
This is a parent POM used for Project Aggregation. Quoting the Introduction to the POM document:
Project aggregation and project inheritance are often used together. Refer to the mentioned document for more details.
Yes, this is what I mean, one project generates one artifact (there are some exceptions but this is true 99% of the time). This is a maven best practice that you should (must?) follow.
I think that the maven way to handle this would be to use assemblies and there is no unique answer to your question (this might be one of the exception to the rule mentioned above). But this won’t prevent you from starting.
Launch your maven command from an aggregating project as we saw (aka “multi-modules build”).