• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Multi-module Maven (jar & war)

 
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thanks in advance for any help or advice, much appreciated.

I have a multi module Maven project. The two modules are

1) client - a jar
2) server - a war

I want to be able to compile, package and deploy my war to Tomcat and then compile and run my jar locally.

Server pom



Client pom



Parent pom



My main Maven command is "package".

But I think I have my life-cycle phases and goals muddled, because not all of my webapp contents are actually copied over to tomcat.

What I want to be able to do is compile, package and deploy server war and THEN compile and run my client jar. As you can see, Im attempting to do this by

* list server as first module in parent pom.
* invoking deployment in "package" phase of server pom.
* then running my client jar.

... but things are working right, and i think its because my server life-cycle never completes.

Regards, Sam
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... bit more detail.

Firs time I run (with no existing war deployed), it works, I get both the war and dir uploaded to tomcat/webapps:

server-1.0-SNAPSHOT.war
server-1.0-SNAPSHOT

... but when i run it again (with existing deployment) I only get the war updated. The directory "server-1.0-SNAPSHOT" is not updated and does not include web xml or classes etc.

Ive also noticed that I am unable to run anything if I just have "deploy" instead of "redeploy".

But perhaps all of this is due to my hacking of life-cycles and build phases?

Regards, Sam
 
Saloon Keeper
Posts: 10523
224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, you should probably have another look at the life-cycle reference. The 'package' phase is used to gather all the resources and compiled binaries, and bundle them in one, well..., package. It's a bad idea to deploy or run something that may or may not have been packaged properly. Because you're forcing the deployment to happen during the packaging phase, what you're deploying might not be the entire package.

Instead of binding your goals to the package phase, try binding them to the deploy phase instead, and run 'mvn deploy'.
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes - but I'm unsure how to structure and order my life-cycle to compile and deploy my war, and then compile and run my jar.

Regards, Sam
 
author & internet detective
Posts: 39435
768
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you call Maven twice? Because it would be far easier to compile/deploy the war in one lifecycle and then use the compile phase of the regular lifecycle from your second run for the client?
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't that a bit of a hack? I mean, I should be able to compile and deploy war and then compile and run jar?

Also, it means editing my parent pom every time which would end up being really time consuming.

 
Stephan van Hulst
Saloon Keeper
Posts: 10523
224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you don't have to edit the POM. Just invoke Maven with different arguments:

mvn -f server tomcat7:redeploy
mvn -f client exec:java
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your continued help.

Im using IntelliJ IDE, not command line - it attempts to build parent pom, so I only have (see attached img).

Regards, Sam
maven_war_jar.png
[Thumbnail for maven_war_jar.png]
 
Stephan van Hulst
Saloon Keeper
Posts: 10523
224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case I recommend creating two different IDEA projects for your modules. That way, you can run them independently from each other, which might even make other things easier.
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really? I mean, this is kind of snowballing out of control and completely circumventing the whole point of Maven?
 
Jeanne Boyarsky
author & internet detective
Posts: 39435
768
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sam wootton wrote:Really? I mean, this is kind of snowballing out of control and completely circumventing the whole point of Maven?


The point of Maven is to have each project create one artifact. (among other things.) For a war, it makes sense to have a parent pom because the war gets deployed with all of it's contents. For example, maybe the war contains 3 jars. You'd have those jars and the wars together.

The client jar is a separate artifacts. It makes sense to have it as a separate project in the IDE with the war as a runtime dependency.
 
Jeanne Boyarsky
author & internet detective
Posts: 39435
768
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As an aside, having the client jar as a separate project gives you extra checking because you know that the client has what it needs to compile (rather than the entire application.)
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but switching entire IntelliJ projects every time a change is made - hardly streamlined workflow
 
Jeanne Boyarsky
author & internet detective
Posts: 39435
768
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does IntelliJ not let you have multiple projects in the same workspace?
 
Stephan van Hulst
Saloon Keeper
Posts: 10523
224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it doesn't, and you're in the luxurious position of having multiple monitors, you can just run multiple instances of your IDE on different screens.
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Single monitor and community intelliJ.

I really can't believe this is the only way - I mean, its just so slow and messy - trying to do something that must be very common
 
Jeanne Boyarsky
author & internet detective
Posts: 39435
768
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:If it doesn't, and you're in the luxurious position of having multiple monitors, you can just run multiple instances of your IDE on different screens.


RAM constrains might prevent that. So I looked it up:

From JetBrains:

IntelliJ IDEA allows you to work with several projects simultaneously, each one in a separate window. The projects are independent, and cannot share information, except for the Clipboard operations. All the projects run in the same instance of IntelliJ IDEA and use the same memory space.


Yuck.
 
Stephan van Hulst
Saloon Keeper
Posts: 10523
224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you think about it it does make sense, because a maven project describes exactly that: a project. It stands to reason that it correlates with a project in your IDE. As a matter of fact, NetBeans understands the POM out of the box, and doesn't even need to generate additional project files.

NetBeans can have multiple projects open at the same time. I'm not sure how IntelliJ IDEA works, but maybe this helps? https://www.jetbrains.com/idea/help/opening-multiple-projects.html
 
Jeanne Boyarsky
author & internet detective
Posts: 39435
768
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:NetBeans can have multiple projects open at the same time.


So can Eclipse.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!