Enjoying this guide? Join our developer community!
Subscribe to Ram N Java on YouTubeHow 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-INFsubfolder with yourweb.xmldeployment descriptor, compiled class files insideclasses/, and third-party libraries insidelib/.
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):
Step 3: Execute the jar Command
Run the following command to bundle all files and subdirectories into a WAR file:
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!
Recommended Related Tutorials from Ram N Java
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 |
No comments:
Post a Comment