79487400

Date: 2025-03-05 18:44:54
Score: 0.5
Natty:
Report link

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
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: 45tera