Tuesday, 18 March 2014

Create war file - JAR tool

Enjoying this guide? Join our developer community!

Subscribe to Ram N Java on YouTube

How to Create a WAR File Using JDK's jar Command Tool

While IDEs like Eclipse make packaging easy, understanding how to generate a WAR (Web Application Archive) file from the command line using the JDK's built-in jar tool is an essential skill for every Java developer and DevOps engineer.

Step 1: Prepare Your Web Application Directory

Before running the packaging command, verify that your project folder follows the standard Java EE web application structure:

  • The root folder contains your public web assets (such as HTML, CSS, JS, and JSP files).
  • The root folder contains the WEB-INF subfolder with your web.xml deployment descriptor, compiled class files inside classes/, and third-party libraries inside lib/.

Step 2: Navigate to the Application Root Directory

Open your Command Prompt (or Terminal) and navigate directly into the root folder of your web project (not the parent directory):

cd path/to/your/webapp-root

Step 3: Execute the jar Command

Run the following command to bundle all files and subdirectories into a WAR file:

jar -cvf MyApplication.war *

Understanding the Command Options

Here is what each flag in the command does:

  • -c: Creates a new archive file.
  • -v: Generates verbose output to the console, showing each file as it is added and compressed.
  • -f: Specifies the output archive file name (e.g., MyApplication.war).
  • *: Instructs the tool to include all files and folders in the current directory.

Once the command finishes, your newly generated .war file will appear directly in your project folder, ready to be deployed to Apache Tomcat or any other servlet container!


Click here to watch in Youtube :  https://www.youtube.com/watch?v=FAxLj2gVHuM

Click the below Image to Enlarge
Create war file - JAR tool

Create war file - JAR tool
Create war file - JAR tool
Create war file - JAR tool


















































See also:

  • Servlets Tutorial
  • All Design Patterns Links
  • No comments:

    Post a Comment

    Tutorials