Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create and deploy war in Intellij

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?

like image 826
user1079065 Avatar asked Mar 23 '16 14:03

user1079065


People also ask

How do I deploy in IntelliJ?

on the main toolbar or press Ctrl+Alt+S to open the Settings/Preferences dialog, and choose the Deployment page (you can access the same page by choosing Tools | Deployment | Configuration from the main menu).

How do you add wars to artifacts in IntelliJ?

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.

How do I create a WAR file?

To create war file, you need to use jar tool of JDK. You need to use -c switch of jar, to create the war file. Go inside the project directory of your project (outside the WEB-INF), then write the following command: jar -cvf projectname.


5 Answers

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.

like image 126
Tomasz Machura Avatar answered Oct 23 '22 16:10

Tomasz Machura


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.

like image 40
Aramis NSR Avatar answered Oct 23 '22 18:10

Aramis NSR


  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

like image 27
Braian Coronel Avatar answered Oct 16 '22 13:10

Braian Coronel


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.

like image 14
harsh hundiwala Avatar answered Oct 23 '22 16:10

harsh hundiwala


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

like image 8
Ganesh Giri Avatar answered Oct 23 '22 16:10

Ganesh Giri