This tool automates the creation of a WAR file for Java web applications. It supports multiple profiles (dev
, test
, prod
, default
), optional version file generation, and deployment to a Tomcat server. The tool can handle different frontend build directories such as React’s dist
or Next.js’s out
.
- Profile-Based Builds: Create WAR files based on specified profiles (
dev
,test
,prod
,default
). - Version File Generation: Optionally generate a version file.
- Deployment: Optionally deploy the WAR file to a Tomcat server.
- Configurable Frontend Directory: Specify the directory for frontend build assets.
- Automatic Configuration:
createWar.config.json
is created with default values if not present. - Clean-Up: Automatically cleans up temporary files after creating the WAR file.
- Ensure you have Node.js installed for building frontend assets.
- Have Python installed if using the script directly. [ only if you want to use script directly | in exe no need of it ]
For convenience, the Python script is packaged into an executable (createWar.exe
) for easy use without needing Python or its dependencies.
-
Download or copy the
createWar.exe
file into the root folder of your project, wherepackage.json
is located. -
Run the
createWar.exe
:- Double-click the
createWar.exe
file to run it. - Or, use the command line (useful for passing arguments):
./createWar.exe
- Double-click the
-
The executable will:
- Read or create the
createWar.config.json
file with default values if it does not exist. - Build the project using the specified profile or the default profile.
- Create the WAR file and optionally deploy it to Tomcat.
- Read or create the
You can pass command-line arguments to customize the behavior. Here’s how to use them:
./createWar.exe --profile dev --tomcatpath "/opt/tomcat/webapps" --deploy --versiongen False --name "customapp.war" --distdir "build"
Argument | Short Flag | Description | Default |
---|---|---|---|
--profile |
-p |
Specify the profile to use (dev , test , prod , default ). |
default |
--tomcatpath |
-tp |
Specify the path to the Tomcat webapps folder. |
Configured path in JSON file |
--deploy |
-d |
Deploy the WAR file to Tomcat. | False |
--name |
-n |
Specify the name of the WAR file. | "myapp.war" |
--versiongen |
-vg |
Set to True to generate a version file. Set to False to skip version generation. |
True |
--distdir |
-dd |
Specify the directory for frontend build assets (e.g., dist for React, out for Next.js). |
"dist" |
-
Generate a WAR file with the
dev
profile:./createWar.exe --profile dev
-
Generate and deploy a WAR file to a custom Tomcat path:
./createWar.exe --profile prod --tomcatpath "/opt/tomcat/webapps" --deploy
-
Skip version file generation and use a custom assets directory:
./createWar.exe --versiongen False --distdir "build"
The script uses a configuration file (createWar.config.json
) to store default values. If the file does not exist, it will be created with default values.
{
"profile": "default",
"tomcatpath": "C:/Program Files/Apache Software Foundation/Tomcat 10.1/webapps", # Set your Tomcat webapps folder location
"deploy": false,
"name": "myapp.war", # The WAR file name determines the context path for your application. Ensure this name matches the context path used to access the application. For instance, if your application should be accessed via '/myapp/', set the name to 'myapp.war'. Failure to align this setting with your application's context path may result in the app failing to load properly.
"versiongen": true,
"distdir": "dist" # Configurable directory for frontend build assets
}
Key | Description | Default |
---|---|---|
profile |
The build profile to use (dev , test , prod , default ). |
default |
tomcatpath |
The path to the Tomcat webapps folder for deployment (if deploy is True ). |
C:/Program Files/Apache Software Foundation/Tomcat 10.1/webapps |
deploy |
Whether to deploy the WAR file to Tomcat. | False |
name |
The name of the WAR file. Ensure that this name matches the context path for your application. For example, if your application is accessed via '/myapp/', set the name to 'myapp.war'. Misalignment can cause the app to fail to load properly. | "myapp.war" |
versiongen |
Whether to generate a version file. | True |
distdir |
The directory for frontend build assets (e.g., dist for React or out for Next.js). |
"dist" |
The distdir
configuration allows you to specify the directory where your frontend build assets are located:
- React: Typically
dist
(default), but can be configured. Make sure to set thehomepage
field inpackage.json
to match the context path used for deployment. - Next.js: Typically
out
for static exports. Ensure that yournext.config.js
is set up to correctly handle the export path.
Context Path Warning: The WAR file name (name
field) directly affects the context path of your application. Ensure that this name matches the context path used to access your application. For example, if you deploy your application to be accessed via http://example.com/myapp/
, the name
should be myapp.war
. Failure to align this with your application's expected context path may result in loading issues.
-
React: In
package.json
, set thehomepage
field:{ "homepage": "/myapp/" }
-
Vite: In
vite.config.js
, set thebase
option:import { defineConfig } from 'vite'; export default defineConfig({ base: '/myapp/' });
Make sure these settings are consistent with your WAR file's context path to ensure correct functionality.
For more detailed information about the version generation script, see the VERSIONREADME.md file.