A WAR (Web Application Archive) file is a compressed file that contains a web application’s files, including servlets, JSPs, HTML, CSS, JavaScript, and deployment descriptor files, for deployment on a Java web server like Apache Tomcat.
Steps to Create a WAR File:
1. Organize the Project Directory
- Ensure your project structure follows the standard web application layout:
2. Use the jar
Command
- Navigate to the parent directory of your web application folder.
- Run the following command:
- Options:
-c
: Create a new archive.-v
: Verbose output.-f
: Specifies the name of the output WAR file.-C
: Change to the specified directory during creation.
- Options:
3. Using Build Tools (Optional)
- Maven:
- Add the following plugin in
pom.xml
:- Run the command:
- The WAR file will be created in the
target
folder.
- Add the following plugin in
- Gradle:
- Add the
war
plugin inbuild.gradle
:- Run the command:
- The WAR file will appear in the
build/libs
folder.
- Add the
Deployment
- Deploy the WAR file to a web server (e.g., Apache Tomcat) by placing it in the webapps directory.
Would you like further assistance with deployment?