Solution
Found out via trial and error that the quotes ("") helped the Windows batch file to handle the expression, and since there was the use of single quotes at the start and end of ('mvn help:evaluate -Dexpression=project.version -q -DforceStdout')
, the Windows CMD does not correctly interpret the code as it would.
As such, we can use a ^
to escape the special character =
in Dexpression
Ammended run.bat
@echo off
:: Get the artifactId dynamically from pom.xml
for /f "delims=" %%i in ('mvn help:evaluate -Dexpression^=project.artifactId -q -DforceStdout') do set ARTIFACT_ID=%%i
:: Get the version dynamically from pom.xml
for /f "delims=" %%i in ('mvn help:evaluate -Dexpression^=project.version -q -DforceStdout') do set VERSION=%%i
:: Run the JAR file with the dynamically extracted artifactId and version
java -jar target\%ARTIFACT_ID%-%VERSION%.jar