How to create and deploy war in Intellij

43,199

Solution 1

IntelliJ has different process to build war:

Goto -> Files -> Project Structure -> Artifacts

In artifacts tab, you will see a small + button on top right corner. Click it and fill up the right panel data such as name and output directory.

Make sure to create the Manifest file. Keep default location for Manifest file.

After building manifest, click apply->Ok.

Now you can go to Build-> Build Artifact.

Your .war file will be ready in the output folder you specified above.

Solution 2

This absolutely works!

First:

Wow, I was reading and trying the answers provided and i couldnt believe why no one mentions the root of the issue which is "NOT MENTIONING THE WAY YOU WANT YOUR OUTPUT TO BE" which is war so lets first tell intellij what we want by adding bellow tag to your pom.xml

<packaging>war</packaging>

where to paste? anywhere inside <project> tag

Now lets talk about the method

You can install "Maven Helper" plugin as it will help beginners nicely, but if your intelij has a good handshake with maven, it will automatically or manually refresh your project and add the war capability to your maven settings ( the panel you see at the right hand side of the editor that mentions Maven) there you click on Plugins and you should see now you have war (org.apache.maven.plugins:maven-war-plugin:xxx) as you click on the + you see many options, war:war and war:exploded are your friends to do what you like

      <!-- Package as an executable jar/war -->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

enter image description here

Use clean to dust off the previous mess, use war:war to create .war file, and for manifest war:exploded will do, if these didnt help for manifest, use the

File | Project Structure and click Artifacts. Click Add + and 'Web Application:war exploded' then it will pop-up your project and select it and hit OK and then go and do Build > Build Artifact.

Good luck.

Solution 3

you can use maven build to create war file. Go to right maven -> Lifecycle -> double click package. You can see your war generated default directory i.e Target

Solution 4

  1. File | Project Structure Ctrl+Shift+Alt+S and click Artifacts.
  2. Click Add + and create a Web Application: Archive For 'Web Application:war exploded'
  3. Build | Build Artifacts > Web Application: war > Build

You should see the artifact <project >/out/artifacts/Web Application_war.war

GL

Source

Solution 5

It took me a while to realise that you can't build a war file with intellij community edition, at least I could not do it looking at answers from this thread.

My approach was to download and activate "Maven Helper" plugin directly from the IDE ie. File->settings->Plugins.

Then, select your pom.xml in the project viewer and in the "Run" tab, you will be able to choose Run new Maven Goal. There simply add the command line "clean install". Your war file (if you selected war in your pom.xml file) will be located under the folder "target" in your project main folder.

Share:
43,199
user1079065
Author by

user1079065

Updated on April 14, 2021

Comments

  • user1079065
    user1079065 about 3 years

    I have a multi-module project in my IntelliJ environment. I want to create and deploy war for only one module in apache tomcat. (IntelliJ comes with default installation of tomcat.)

    I have worked almost four years with Eclipse and started with IntelliJ like three days back. Just the way we right click on the project in eclipse and say export as war and it directly deploys in my app server, can I do same / similar in IntelliJ?

    Any help will be helpful.

    Thanks

    PS : may be stupid to ask but would mac / windows make difference?

  • IcyBrk
    IcyBrk over 5 years
    this is only for IntelliJ Ultimate, can I create war with IntelliJ Community, thank you.
  • cp.
    cp. almost 3 years
    Even after clean and rebuild I find that this builds a war that loads into TC but fails with a 404. Anyone else getting same/solution?
  • Daryll David Dagondon
    Daryll David Dagondon almost 3 years
    Adding <packaging>war</packaging> is crucial. It works. This must be the accepted answer.
  • Aramis NSR
    Aramis NSR almost 3 years
    @DaryllDavidDagondon Happy it helped :)