Eclipse Neon – Export Dynamic Web Project to WAR File

This post shows how to export a dynamic web project in Eclipse Neon to a WAR file (Web Archive). The WAR export can be configured to include dependent JAR files (Java Archive). The WAR file (aka Web Module) can then be deployed to an application server, here Tomcat 9, to run the web application.

Summary

  1. Configure Deployment Assembly for Dynamic Web Project
  2. Export Dynamic Web Project to WAR File

Related Posts

1  Configuring Deployment Assembly for Dynamic Web Project

  • An Eclipse Neon web project with Spring 5 MVC support is used to show how to export to a WAR file.
  • For step-by-steps instructions on how to create a web project with Spring in Eclipse Neon, see the post:
  • There is a controller called MyController.java and a JSP called HelloWorld.jsp.
  • Two user libraries called JSTL-1.2.5 and Spring5 have been created and added to the build path.
Eclipse Neon - View Dynamic Web Project Structure in Project Explorer
  • Right-click on the project name, here SpringWebProject and select Properties in the context menu.
Eclipse Neon - Open Dynamic Web Project Properties
  • Select Deployment Assembly on the project properties dialog.
Eclipse Neon - Dynamic Web Project Properties, View Deployment Assembly
  • The dependent user libraries need to be added here so that they are included in the WAR file.
  • Click on the Add button to create a new Assembly Directive.
Eclipse Neon - Dynamic Web Project, Add Assembly Directive and Select Directive Type
  • From the list of Directive Types, select Java Build Path Entries and click Next.
Eclipse Neon - Dynamic Web Project, New Assembly Directive, Select Java Build Path Entries
  • Select the user libraries, here Spring5 and JSTL-1.2.5 and click Finish.
Eclipse Neon - Dynamic Web Project, View Completed Deployment Assembly
  • Click on OK to complete the deployment assembly configuration.

2  Export Dynamic Web Project to WAR File

  • In the Eclipse Neon Project Explorer, right-click on the project name and select Export > WAR file from the context menu. For more information on WAR files, see The Java EE 5 Tutorial on Web Modules by Oracle.
Eclipse Neon - Dynamic Web Project Context Menu, Select Export To WAR File to Export Dynamic Web Project to WAR File
  • Use the Browse button to select the destination for the new WAR file and then click on Finish.
Eclipse Neon - Dynamic Web Project, Using WAR Export Wizard to Export Dynamic Web Project to WAR File
  • The WAR file will be created in the specified destination folder.
Eclipse Neon - View WAR Export Destination Folder Contents
  • The WAR file can be unzipped using the Archive Utility on Mac OS or the Windows ZIP tool.
  • The screen shot below shows the content of the WAR file, including the JAR library dependencies.
Eclipse Neon - Unzip WAR File and View Contents
  • The WAR file can now be deployed to a Servlet Container such as Tomcat or to a Java EE compliant Application Server such as JBoss.

Leave a Reply