Skip to content

Commit 770cec8

Browse files
committed
docs(notes): update 2025-03-21-control-m-en.md
1 parent 8f8ccfc commit 770cec8

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed

notes/2025-03-21-control-m-en.md

+163
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,166 @@ Using the Control-M client on Windows involves interacting with the Control-M/En
128128

129129
This should give you a solid start with the Control-M client on Windows! Let me know if you need help with a specific task, like troubleshooting a job.
130130

131+
---
132+
133+
To use Control-M to deploy a Spring Boot Java Maven project on a Windows system, you’ll need to create a `.bat` (batch) file to handle the Maven build and deployment steps, then configure Control-M to execute that script as a job. Below, I’ll provide example `.bat` scripts and explain how to set them up in Control-M.
134+
135+
---
136+
137+
### Example Scenario
138+
You have a Spring Boot project that uses Maven to build and run a JAR file. The goal is to:
139+
1. Build the project (`mvn clean package`).
140+
2. Deploy/run the resulting JAR file (`java -jar`).
141+
142+
---
143+
144+
### Example Batch Files
145+
146+
#### 1. Simple Build and Run Batch File
147+
This script builds the project and runs the JAR in one go.
148+
149+
```bat
150+
@echo off
151+
echo Starting Spring Boot deployment...
152+
153+
REM Set your project directory (adjust this path)
154+
cd C:\Projects\MySpringBootApp
155+
156+
REM Run Maven to clean and build the project
157+
call mvn clean package
158+
159+
REM Check if build was successful
160+
if %ERRORLEVEL% NEQ 0 (
161+
echo Maven build failed!
162+
exit /b %ERRORLEVEL%
163+
)
164+
165+
REM Run the Spring Boot JAR (assumes it's in target folder)
166+
java -jar target\MySpringBootApp-1.0-SNAPSHOT.jar
167+
168+
echo Deployment complete!
169+
```
170+
171+
- **Explanation**:
172+
- `cd`: Navigates to your project folder.
173+
- `mvn clean package`: Builds the project, creating a JAR in the `target` folder.
174+
- `if %ERRORLEVEL% NEQ 0`: Checks for Maven errors and exits if the build fails.
175+
- `java -jar`: Runs the Spring Boot application.
176+
177+
#### 2. Build-Only Batch File (Separate Deployment)
178+
This script only builds the project, useful if deployment is handled separately.
179+
180+
```bat
181+
@echo off
182+
echo Building Spring Boot project...
183+
184+
REM Set your project directory
185+
cd C:\Projects\MySpringBootApp
186+
187+
REM Run Maven build
188+
call mvn clean package
189+
190+
REM Check build status
191+
if %ERRORLEVEL% NEQ 0 (
192+
echo Build failed!
193+
exit /b %ERRORLEVEL%
194+
)
195+
196+
echo Build successful! JAR is ready in target folder.
197+
```
198+
199+
#### 3. Deploy-Only Batch File
200+
This runs an already-built JAR, useful for redeployment without rebuilding.
201+
202+
```bat
203+
@echo off
204+
echo Deploying Spring Boot JAR...
205+
206+
REM Navigate to the folder with the JAR
207+
cd C:\Projects\MySpringBootApp\target
208+
209+
REM Run the JAR
210+
java -jar MySpringBootApp-1.0-SNAPSHOT.jar
211+
212+
echo Application started!
213+
```
214+
215+
---
216+
217+
### Prerequisites
218+
- **Maven Installed**: Ensure Maven is installed on the Windows machine where the Control-M agent runs (`mvn -version` should work in Command Prompt).
219+
- **Java Installed**: Confirm Java is available (`java -version`).
220+
- **Control-M Agent**: The agent must be installed and running on the Windows machine.
221+
- **Project Ready**: Your Spring Boot project should be in a folder (e.g., `C:\Projects\MySpringBootApp`) with a valid `pom.xml`.
222+
223+
---
224+
225+
### Configuring Control-M to Deploy the Spring Boot Project
226+
Here’s how to set up Control-M to execute these scripts:
227+
228+
#### Using Control-M/EM GUI
229+
1. **Launch Control-M Client**
230+
Open the Control-M/Enterprise Manager GUI on your Windows machine and log in.
231+
232+
2. **Create a New Job**
233+
- Go to the **Planning** tab.
234+
- Click “New Job” and select “OS” (Operating System) job type.
235+
236+
3. **Define the Job**
237+
- **General Tab**:
238+
- Name: `DeploySpringBootApp`
239+
- Host: The name of the Windows machine with the Control-M agent.
240+
- **Actions Tab**:
241+
- Command: `C:\Scripts\build_and_run.bat` (adjust path to where you saved the `.bat` file).
242+
- Alternatively, use `cmd /c C:\Scripts\build_and_run.bat` to explicitly run via Command Prompt.
243+
- **Scheduling Tab**:
244+
- Set it to run daily at a specific time (e.g., 2 AM) or on-demand.
245+
- **Conditions Tab** (Optional):
246+
- Add dependencies if this job relies on another (e.g., a backup job finishing first).
247+
248+
4. **Save and Load**
249+
- Save the job and load it into the active environment.
250+
251+
5. **Monitor Execution**
252+
- Go to the **Monitoring** tab.
253+
- Watch the job run. Check the output/log for success (`Deployment complete!`) or errors (`Build failed!`).
254+
255+
#### Example: Separate Build and Deploy Jobs
256+
If you split build and deploy into two scripts:
257+
- **Build Job**:
258+
- Command: `C:\Scripts\build_only.bat`
259+
- Name: `BuildSpringBoot`
260+
- **Deploy Job**:
261+
- Command: `C:\Scripts\deploy_only.bat`
262+
- Name: `RunSpringBoot`
263+
- Condition: Add a dependency so `RunSpringBoot` runs only after `BuildSpringBoot` succeeds.
264+
265+
---
266+
267+
### Tips for Success
268+
- **Path Configuration**: Ensure `JAVA_HOME` and Maven’s `bin` directory are in the system PATH, or specify full paths in the `.bat` (e.g., `C:\Maven\bin\mvn`).
269+
- **Permissions**: The Control-M agent’s user must have access to the project folder and execution rights.
270+
- **Logging**: Add `>> C:\Logs\controlm.log 2>&1` to the `.bat` commands to capture output for troubleshooting.
271+
- **Testing**: Run the `.bat` manually first in Command Prompt to verify it works before scheduling in Control-M.
272+
273+
---
274+
275+
### Sample Workflow Output
276+
When Control-M runs `build_and_run.bat`, you might see in the job log:
277+
```
278+
Starting Spring Boot deployment...
279+
[INFO] Scanning for projects...
280+
[INFO] BUILD SUCCESS
281+
Deploying Spring Boot JAR...
282+
[Spring Boot startup logs]
283+
Deployment complete!
284+
```
285+
286+
If it fails (e.g., Maven error), the log will show:
287+
```
288+
Build failed!
289+
```
290+
291+
---
292+
293+
This setup automates your Spring Boot deployment via Control-M! Let me know if you need help tweaking the scripts or job configuration further.

0 commit comments

Comments
 (0)