How can I have IntelliJ build artifacts with a specific maven profile?

My maven profiles effect the output of my artifacts. Specifically the maven profile inserts certain database connection properties into my WEB-INF/persistence-context.xml which vary between production and development.

On the Project Structure -> Artifacts tab I have two options. web:war and web:war exploded. I'm using web war:exploded, and that works fine, but I want to be able to specify a particular maven profile to use when putting together the web war:exploded artifact. Is there a way to do that?

To the best of my knowledge, there is not. Out of curiosity, why not just build via a maven (in IDEA) run configuration where you can specify a profile rather than via the built in Make? The resultant artifact would then contain the desired persistence-context.xml file. You can configure any run configuration (such as launching a web server, running unit tests, etc.) to run maven (including a specified profile) before launch rather then running the internal Make action. You can either have two nearly identical run configs which specify different profiles, or you the "Show this page" option in the run configuration so you can modify the profile before running.


I was able to do as you mentioned by creating a maven run profile, and attaching it to the "do this before you deploy" for the Tomcat run profile. My confusion arose because I did not realize that I could use something other than the IntelliJ make process to package stuff up for the Tomcat install.


Please sign in to leave a comment.