0

I'm developing a modular project with maven that have the following skeleton:

 |-- parent  (pom packaging)
 |-- model   (jar packaging)
     pom.xml
 |-- services (jar packaging)
     pom.xml
 |-- web-app  (jar packaging)
     pom.xml

pom.xml

I'm using the jetty plugin as embedded servlet container, the problem that many time I need to run the war project and from my IDE or from web-app folder i run mvn jetty:run. This compile,test,packed,... the web-app but not the others modules. Summarizing I would want than when I run mvn jetty:run all modules will come compiled,tests,packed. How can I configure jetty plug-in to do this?

EDIT 1

Suppose that I'm modifing some cleasses on the services module on eclipse, I have the following configuration on eclispe:

enter image description here

In this way i'm losing the changes about service module, and the i have to run mvn -pl service clean install from my command line and then I can use the eclipse configuration and have all updates. I would want to do everythings just with a maven build on eclipse.

Skizzo
  • 2,883
  • 8
  • 52
  • 99

1 Answers1

0

You could have a multi-module project (preferably different from the parent project) and perform mvn clean install on all projects, then mvn jetty:run on your webapp project.

So you would run something like mvn clean install jetty:run on the multi-module project. I didn't test it myself, as I don't run my servers this way, as explained in the comments.

I think the multi-module approach is the best, because in the "normal" usage of maven, there is no way to tell a Project B that relies and a jar project A to recompile A. The expected behavior is to look in local/remote repos for the jar.

However, I strongly discourage the usage of several projects (model, dao, service ...) if the projects don't have a different lifecyle. If you share the model across projects, if a jar project is reused in several war projects, this makes sense. And in this case, you will have different version number, might want to rebuild all modules or not etc....

If this is not the case, you will struggle with the added complexity without enjoying any benefits.

Edit : in your case, you need the modular approach because the model is shared with other apps. But in this case, unless your other apps have the same lifecycle, you cannot be that flexible and modify the model without being sure that you don't impact the other projects. So you will need another version number, maybe SNAPSHOT, and in this case running jetty in Eclipse is imo the simplest solution to run the latest version of your code.

Samuel EUSTACHI
  • 3,116
  • 19
  • 24
  • I need to split my project, because my model is using from different others project, my problem is that I would want to execute compile,test,packed of all modules and start the web-app using a only eclipse maven build. Is this possible? – Skizzo Feb 20 '15 at 15:08
  • I think that in this case I would use the multi-module approach, indeed. But sorry to stress out something that might not be a reply to your exact question and look off topic, but usually, when I want to install / deploy a war or jar, I use the command line, and when I want to run / debug, I do it from IDE. In this second case, the full maven build process is not so relevant because if the projects are all imported and available in Eclipse, the jars in .m2 are not used, as Eclipse plugin has its own way. This is a bit tricky to understand but handy at it allows easy debugging. – Samuel EUSTACHI Feb 20 '15 at 15:17
  • My point was that if you have the service project opened in Eclipse, And you deploy your web project using the embedded plugin of the container (tomcat, jetty ....) you will be able to use the current code of the service, and even enter in this code with the debugger, without any action other than redeploying the webapp in Eclipse. – Samuel EUSTACHI Feb 20 '15 at 15:45
  • Ok, if the container is run, I'm able to use the corrent code, but if I modified the code in the service module when the container is down, when i deploy my web-app I don't see these change – Skizzo Feb 20 '15 at 16:11
  • In this case, running mvn install or Project->Clean of all your projects, you should run the last code. Personnaly, I prefer the command line build when the dependencies have a change. Still, regardless on how I build the project, for debugging I prefer to run it with the IDE. Imo running the container in maven is more interesting for automated integration testing. – Samuel EUSTACHI Feb 23 '15 at 10:38
  • Think for the answers but these don't solve my problem, because i have to do always two operation to deploy my web-app and see the changes, I would like it in a only Eclipse Mazen configuration – Skizzo Feb 24 '15 at 08:49
  • You can do it all-in-one with the multi-module project. Sorry I made it more complicated by proposing another solution. So basically what you ant is to run mvn clean install jetty:run on the multi-module project – Samuel EUSTACHI Feb 24 '15 at 16:51
  • Multi-module project is the standard way to rebuild a set of projects, in the appropriate order, thanks to the maven reactor – Samuel EUSTACHI Feb 24 '15 at 16:52