How can I create a war file of my project in NetBeans?
-
3I advise that you write an Ant or Maven script to build your war file and not rely on a specific IDE. – Nick Holt Jun 17 '09 at 14:28
-
can that .war be deployed with tomcat ?? as in, can i just go ahead and place it in the /webapp directory of tomcat ?? Well i know i'm kinda late here but i just happened to bump into this forum and i've been troubled by this . it's not working when i tried – May 18 '11 at 14:32
-
can i change the detination folder instead of dist folder to other lets say , mapped network folder – shareef Jun 23 '14 at 18:46
10 Answers
It's possible that you already have a war file and don't know it - netbeans does most of the work for you and I believe it creates a distributable war file by default. If you created a web project and successfully built it, it will be in the "dist" directory off your project root.

- 954
- 1
- 10
- 18
-
1This war file is not in the webapps folder of the tomcat. How is it opened by Tomcat when it is in a different folder? – Koray Tugay Feb 23 '13 at 23:24
-
This is true, but only if the dist directory has been created first. See arkilus' answer below on running ant do-dist to create this directory. – Rónán Ó Braonáin Apr 19 '13 at 18:22
-
6In Netbeans 7.4 - right click on the project select Properties-> Build -> Packaging. There you will see Compress WAR File. Otherwise it doesn't create the dist folder with a war file in it. – xmux Mar 21 '14 at 14:42
As DPA says, the easiest way to generate a war file of your project is through the IDE. Open the Files tab from your left hand panel, right click on the build.xml file and tell it what type of ant target you want to run.

- 1,330
- 1
- 17
- 26
Right click your project, hit "Clean and Build". Netbeans does the rest.
under the dist directory of your app, you should find a pretty looking .war all ready for deployment.

- 7,130
- 12
- 56
- 72
-
The problem with this is that it cleans and builds all projects in the libraries, too. For a large project this can be annoyingly time-consuming, especially if you've only made a handful of changes to the webapp project and therefore don't need to recompile everything else. – daiscog Jun 27 '16 at 11:46
Netbeans will create the Ant script for you, it uses Ant to build anyway. But if you want to get the war file, just build your project. The .war file will be located in /yournetbeanshomedirectory/yourproject/dist/yourwar.war
You can check out the ant build script it uses by looking at the build.xml file in your project directory. Might help you feel a little more comfortable using ant to do builds.

- 354
- 1
- 6
-
I had a project in Netbeans with Maven and I was missing the .war-file. After hitting `build` it was generated in the `target` folder. – bomben Jun 08 '20 at 12:23
This worked for me:
1.Right click pom.xml
2.Run Maven > Goals
3.Edit maven goals
Results: war build in /target folder
Packaging webapp
Assembling webapp [WeatherDashboard] in [C:\Users\julian.mojico\Documents\NetBeansProjects\WeatherDashboard\target\WeatherDashboard-1.0-SNAPSHOT]
Processing war project
Webapp assembled in [672 msecs]
Building war: C:\Users\julian.mojico\Documents\NetBeansProjects\WeatherDashboard\target\WeatherDashboard-1.0-SNAPSHOT.war
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 1:41.633s
Finished at: Tue Sep 05 09:41:27 ART 2017
Final Memory: 18M/97M
------------------------------------------------------------------------

- 2,393
- 1
- 23
- 24
If NetBeans haven't created your dist
folder, execute the do-dist
ant target:
In commandline navigate to the directory of your project, the one containing a build.xml file
> ant do-dist
If ant runs fine (most likely), your dist
folder will be created, containing the .war
file.

- 2,507
- 4
- 28
- 45
-
1This solved my problem, thanks! Now every time I build, the .war is output to the dist directory as expected. – Rónán Ó Braonáin Apr 19 '13 at 18:21
I had to right-click the build.xml file and choose "run". Only then would the .war file be created.

- 103
- 1
- 7
Simplest way is to Check the Output - Build tab: It would display the location of war file.
It will have something like:
Installing D:\Project\target\Tool.war to C:\Users\myname.m2\repository\com\tool\1.0\Tool-1.0.war

- 2,119
- 1
- 25
- 24
It is in the dist folder inside of the project, but only if "Compress WAR File" in the project settings dialog ( build / packaging) ist checked. Before I checked this checkbox there was no dist folder.

- 709
- 6
- 11