3

I have the following bat script:

@echo off
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_32
set JRE_HOME=C:\Program Files\Java\jdk1.6.0_32\jre
set Path=%JAVA_HOME%\bin;%Path%

cd C:\project
mvn validate compile package db-migration:migrate -DskipTests
REM script exits here, the second line never been executed
java  -jar target/compiled_tar.jar

The last line never been executed. The "mvn..." is successfully done, the compiled_tar.jar is created, the output is:

[INFO] BUILD SUCCESS

If I insert the PAUSE command between last and previous lines the PAUSE also never been occurred. Why?

Eric J.
  • 147,927
  • 63
  • 340
  • 553
odiszapc
  • 4,089
  • 2
  • 27
  • 42
  • mvn might be quitting the entire process. I've had the same problem with some ant directives in the past, hope to see a solution as well. – TheZ Jul 03 '12 at 23:14
  • Could do `mvn … && true` I think cmd may not have a true command see have to replace with `echo.` (almost the same, but prints a blank line). The trouble with this is you don't know if there was an error. What are the error codes for mvn? – ctrl-alt-delor Jul 03 '12 at 23:19
  • see http://stackoverflow.com/a/1385644/537980 – ctrl-alt-delor Jul 03 '12 at 23:25
  • Possible duplicate of *[Why does only the first line of this Windows batch file execute but all three lines execute in a command shell?](https://stackoverflow.com/questions/4036754/why-does-only-the-first-line-of-this-windows-batch-file-execute-but-all-three-li)* - it is even the same BAT file, "mvn". – Peter Mortensen Nov 01 '18 at 16:28

2 Answers2

12

mvn is itself a .bat file, so (for compatibility with MS-DOS 1.0) Windows will stop executing your batch file. To fix this, use the call command:

call mvn validate compile package db-migration:migrate -DskipTests
Neil
  • 54,642
  • 8
  • 60
  • 72
0

Using this Maven command (set maven_batch_pause=on) will solve this perfectly:

@echo off

set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_32
set JRE_HOME=C:\Program Files\Java\jdk1.6.0_32\jre
set Path=%JAVA_HOME%\bin;%Path%

set maven_batch_pause=on
cd C:\project
mvn validate compile package db-migration:migrate -DskipTests

REM The script exits here, and the second line will never be executed
java  -jar target/compiled_tar.jar
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
neptune
  • 1,124
  • 2
  • 9
  • 17