You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: notes/2025-03-21-control-m-en.md
+163
Original file line number
Diff line number
Diff line change
@@ -128,3 +128,166 @@ Using the Control-M client on Windows involves interacting with the Control-M/En
128
128
129
129
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.
130
130
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.
- 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