Using maven overlays in webapp run configuration using IntelliJ?
Asked Answered
W

1

11

I am developing a magnolia based website. I am using the webapp archetype to create a new web application. Using the command line I am able to produce a WAR and deploy that in my container (Tomcat). I then run it and it works fine.

My next step was to import my project structure into IntelliJ. IntelliJ sees everything fine, and is able to compile it all. I have tested this by doing a maven clean first, and then let IntelliJ do the rest (rebuild project).

The last step is to let it run in my container. I have set up the run configurations before for web apps (they do not use war overlays), and they worked just fine. In this case I set it up just like before and point to my exploded webapp artifact.

Once I run tomcat, it does not find my webapp. I find that the overlay has not been merged into the target directory of the project (which normally is the case when just doing maven install). IntellJ however has created an overlays directory in my project and unpacked the (overlay/super) WAR file in there.

I get it working when I do a maven install myself, and then run Tomcat in IntelliJ. Which is obvious, because all sorts of needed files are now in my target directory (like a web.xml for example :)).

What I want is this: - IntelliJ knows that when it runs Tomcat, it should have prepared the target directory just like "mvn install" or "mvn package" would do.

What it does: - It does something in between. It does create a target dir, and it does copy resources from the webapp project. It does not overlay any WAR dependency, hence the webapp target dir is incomplete.

Anyone has any tips to solve this?

Waistcloth answered 21/9, 2011 at 9:40 Comment(0)
W
10

I found that checking the "run maven goal" checkbox in the run configuration, and setting mvn package does make it work.

Waistcloth answered 21/9, 2011 at 10:42 Comment(3)
Will this allow me to 'Update classes' as well? Or would I have to redeploy to see every change?Shiism
When you do update classes, they will be loaded in memory and it will work. But do note that when you are using multiple dependencies, the next time you start your container you need to make sure the container (ie tomcat) is also looking at your latest sources of the dependencies. I found this quite cumbersome, I had to mvn clean install these dependencies to make sure they where in my local repo. And that way the mvn package goal would pick them up correctly.Waistcloth
@StefanHendriks: Thanks for the tip. I had a similar issue where my overlay definition was being ignored by IntelliJ. It seems that IntelliJ ignores some of the config of the maven-war-plugin when it builds a the webapp using its own internal build mechanism. Telling it to delegate the war build to maven itself means that the whole war-plugin config is honoured.Fuhrman

© 2022 - 2024 — McMap. All rights reserved.