1

I'm have a "bat" file with some maven commands which are pretty long so I tried to create a single file with MVN commands to execute. I call my bat file in cygwin as:

$./mvncommand.bat

Sample MVN commands in my file:

mvn install:install-file -DgroupId=org.openhealthtools.ihe -DartifactId=atna.auditor -Dversion=1.2.0 -Dfile=resources/lib/org.openhealthtools.ihe.atna.auditor_1.2.0.jar -Dpackaging=jar -DgeneratePom=false

mvn install:install-file -DgroupId=org.openhealthtools.ihe -DartifactId=atna.context -Dversion=1.2.0 -Dfile=resources/lib/org.openhealthtools.ihe.atna.context_1.2.0.jar -Dpackaging=jar -DgeneratePom=true

Strangely, only the first mvn install is executed and the all is ok. But how to make Cygwin call the rest of the mvn commands?

Thank you.

JR

code-gijoe
  • 6,949
  • 14
  • 67
  • 103

2 Answers2

3

Maven (mvn) is a batch file and running batch files from another batch file must be done with call.

So change what you have into

call mvn ...

and it should work.

This has nothing to do with Cygwin, by the way.

Joey
  • 344,408
  • 85
  • 689
  • 683
  • Thanks! Just me being a noob and all. Solved my problem. – code-gijoe Feb 02 '11 at 18:59
  • @code: It's a problem many Java-based applications have when they decide that a batch file calling `java -jar maven.jar` or similar would be enough. It works fine from the console but unless you know it's a batch file it calls for trouble from inside batch files. – Joey Feb 02 '11 at 19:02
  • I removed the ".bat" extension and set it to ".sh" and now it works without the "call" before each mvn command. Probably windows was starting a process for the bat file and hence out of cygwin scope. – code-gijoe Feb 02 '11 at 21:56
  • @code: Of course, `.bat` gets executed by `cmd`. That's why I meant this has nothing to do with Cygwin. – Joey Feb 02 '11 at 22:46
0

It's possible that your first mvn command is returning an error code. In Windows's cmd, this will cause all subsequent commands to not run. This might be the behavior you want, but you should consider using a *nix-like shell rather than a Windows batch file since you're already using Cygwin.

For example, you could put both commands in a file named mvncommand with your shell of choice.

#!/usr/bin/bash
mvn install:install-file -DgroupId=org.openhealthtools.ihe -DartifactId=atna.auditor -Dversion=1.2.0 -Dfile=resources/lib/org.openhealthtools.ihe.atna.auditor_1.2.0.jar -Dpackaging=jar -DgeneratePom=false

mvn install:install-file -DgroupId=org.openhealthtools.ihe -DartifactId=atna.context -Dversion=1.2.0 -Dfile=resources/lib/org.openhealthtools.ihe.atna.context_1.2.0.jar -Dpackaging=jar -DgeneratePom=true
dfb
  • 13,133
  • 2
  • 31
  • 52
  • No, it's not an error and no, a non-zero return code won't exit a batch file. That's nonsense. – Joey Feb 02 '11 at 18:58
  • Ok - I tried testing a batch file calling another batch file with SET ERRORLEV=1 and the subsequent calls don't execute - some difference in the way nested batches get called? – dfb Feb 02 '11 at 19:02
  • Try `help call`. `set ERRORLEV=1` accomplishes nothing, actually. – Joey Feb 02 '11 at 22:46