Create a WAR file for a Java web application in NetBeans

Configure the web application

Add the web.xml file

The wb.xml file contains the web application configuration values for the webserver. I has to be in the WEB-INF directory of the web applicaion. To add the web.xml file to your NetBeans Java web application

  1. Right-click the Netbeans project, and select New -> Other
  2. In the New File window select XML -> XML Document, and click the Next button,
  3. In the New XML Document window enter web.xml as the name of the file, and click the Browse… button to select the location,
  4. Select the src\main\webapp\WEB-INF folder, and click the Select Folder button,
  5. In the New XML Document window click the Next button,
  6. In the New File window keep the Well-formed Document radio button selected and click the Finish button,
  7. NetBeans creates the XML file in the Web PAges WEB-INF folder on the web project.

Build the WAR file

To create a WAR file for a Java web application in NetBeans 8.2

  1. In the NetBeans IDE select the Files tab,
  2. Right-click the pom.xml file and select Run Maven > Goals…
  3. In the Run Maven window enter compile war:war into the Goals field,
  4. Select the Remember as checkbox and enter Compile war for the name,
  5. The WAR file is generated in the target directory of the Java web project.
  6. The next time you want to build the WAR file, the Compile war option will be visible in the Run Maven menu.

Leave a comment

Your email address will not be published. Required fields are marked *