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
.
dev
, test
, prod
, default
).createWar.config.json
is created with default values if not present.Have Python installed if using the script directly. [ only if you want to use script directly | in exe no need of it ] |
createWar.exe
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, where package.json
is located.
createWar.exe
:
createWar.exe
file to run it../createWar.exe
createWar.config.json
file with default values if it does not exist.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"
createWar.config.json
)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.
createWar.config.json
:{
"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:
dist
(default), but can be configured. Make sure to set the homepage
field in package.json
to match the context path used for deployment.out
for static exports. Ensure that your next.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.
package.json
, set the homepage
field:
{
"homepage": "/myapp/"
}
vite.config.js
, set the base
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.