IntelliJ IDEA: Maven, project compilation and deployment

24,303

Intelli J doesn't use maven to build the project it uses its own build process. It uses the pom file as a description of the project.

This means a couple of things, if you want to build an artifact such as a war file when running in tomcat then all you have to do is tell IntelliJ to build the war in the Run/Debug Configurations dialog. IntelliJ will automatically build any artifacts you specify under the deployment tab of your run/debug configuration. So if you specify the exploded war it will build the exploded war, if you specify the regular war it will build the regular war.

Occasionally people need to run custom plugins or build targets in which case you can configure IntelliJ to run the custom maven goals.

You can also tell intellIJ to run the maven package goal rather than build the artifact. IntelliJ will deploy whatever is under the target directory to tomcat.

The important take away is IntellIJ is using two separate build systems. You need to tell each build system what to do. And you need to tell IntelliJ which build system to use for what. IntelliJ will by default use it's own build system once a project has been imported, unless you tell it to use maven for something.

While IntelliJ will build the artifact you specify in the pom file it won't do things like deploy them your artifact repository (local or other wise) unless you click on the deploy target in the Maven tools window.

Also if you change your pom file and don't have auto re-import enabled those changes won't be reflected in your project until you click the force re-import option from the maven tools window.

Share:
24,303

Related videos on Youtube

Igor Konoplyanko
Author by

Igor Konoplyanko

I wanna be in R&D.

Updated on April 07, 2020

Comments

  • Igor Konoplyanko
    Igor Konoplyanko about 4 years

    Can someone explain me IntelliJ IDEA's workflow of compilation, deployment and packaging with binded maven project ?

    I've encountered some misunderstanding when I'm starting tomcat server via IDEA's debug mode. For example I have one artifact - war archive. As I understand when I'm running debug mode - IDEA recompiles and updates changed code into war-archive.

    But what happens with packaged maven artifact ? Does IntelliJ updates it ? Or I have to set 'Buld maven before startup' option to be sure that changed code will be uploaded to environment ?

  • Karthik Ramachandran
    Karthik Ramachandran about 13 years
    IntellIJ now automatically loads a pom.xml and generates all the files it needs (ipr, iml, and iws) So you don't have to use the Maven IDEA plug in any more.
  • Jon Onstott
    Jon Onstott about 13 years
    Telling IntelliJ to run the 'package' goal would be great for me since I have resource filtering done on the packaging phase... would that work slower than using IntelliJ's artifacts? Thanks.
  • Karthik Ramachandran
    Karthik Ramachandran about 13 years
    @jon I think that might be marginally slower mainly because maven will try and pull all the poms. If you run in offline mode, it'd probably be the same.
  • John Lockwood
    John Lockwood over 10 years
    I was just setting up a Jersey RESTful web service to run on Tomcat, and this was helpful. Thanks.
  • James Robinson
    James Robinson about 8 years
    Its great that I can "tell intellIJ to run the maven package goal rather than build the artifact", but how ...