如何在bat文件中执行多个maven命令?

时间:2011-07-04 14:53:35

标签: windows maven batch-file

我制作了一个蝙蝠文件,如:

mvn clean;
mvn package;

但它不起作用,只执行第一个命令。

有人可以帮助我吗?

9 个答案:

答案 0 :(得分:207)

使用

call mvn clean
call mvn package

请注意,批处理文件中不需要分号。您需要使用call的原因是mvn本身是一个批处理文件,批处理文件需要使用call相互调用,否则控件不会返回给调用者。 / p>

如果您希望后续命令回显到命令行(在批处理输出中显示),则必须在echo on完成后执行call mvn(在下一行)。这是因为mvn关闭了回声并且没有将其重新打开。

答案 1 :(得分:25)

Joey的答案很棒,但也许一个更完整的代码示例将帮助像我这样的其他人,他们也在解决从Windows中的批处理文件构建多个maven项目的类似问题:

REM maven itself uses a batch file so each mvn must be preceded by "call"
REM the -f flag specifies where the pom.xml is found for the project
REM mvn install will save the target output to %userprofile%\.m2\repository ...

call mvn install -f c:\Users\John\workspace\PropertiesReader\pom.xml

call mvn install -f c:\Users\John\workspace\PropertiesWriter\pom.xml

答案 2 :(得分:13)

您还可以使用以下单行:

call mvn clean package 

答案 3 :(得分:8)

我有更多的项目要运行,我创造了这样的蝙蝠:

@echo off
SET DEVELOPMENT_HOME=C:\Projects

cd %DEVELOPMENT_HOME%\Project1\
call mvn clean install

cd %DEVELOPMENT_HOME%\Project2\
call mvn clean install

答案 4 :(得分:6)

如果要在父文件中调用另一个批处理文件,请使用“call”,以便该控件将返回到父批处理文件,并且将继续执行。

例如调用mvn clean install

答案 5 :(得分:3)

观察到的bahaviour来自MS-DOS 1.0的时间,并且出于兼容性原因而保留,因为解决方案应该通过以下方式使用Windows 调用功能:

call mvn clean
call mvn package

“call”从另一个执行一个批处理程序,并将其解释为子程序。

答案 6 :(得分:0)

我们可以使用以下代码来构建Maven并将其传递给任何unix文件夹以用于开发目的

SET projectName=commonutil
cd %gitpath%\%projectName%
call mvn clean install -DskipTests=true %password%
IF %ERRORLEVEL% EQU 0 (Echo No error found) ELSE goto exitdoor 
SET jarpath="%gitpath%\%projectName%\target\%projectName%-0.0.1-SNAPSHOT.jar"
copy /Y %jarpath% "%libpath%"
scpg3 %jarpath% %ssh_profile_name%@%hostname%:%dev_lib_folder_name%

答案 7 :(得分:0)

Use these commands in batch file to run ur script. Keep your batch file where 
you pom.xml file is housed

set ProjectPath=C:\TetonWorkSpace\PeriodicApplicationCheck
cd %ProjectPath%
mvn clean test -Dxmlfile=Smoke.xml
pause

To Create a Task in Task scheduler:
1. Follow steps as prescribed to create task
2. In the action tab, just place the path of ur batch file as shown below
    C:\TetonWorkSpace\PeriodicApplicationCheck\testng.bat
3. You can ignore the rest two options like Add Argument and Start in. Use it 
   only when there are certain conditions to be used without which the script 
    becomes dysfunctional.

Placing path of the batch file in Action Tab.

答案 8 :(得分:-2)

使用

致电mvn clean package

sample
------
echo %test%
cd %test%\ManaulActionAddNotes-test
call mvn clean
cd %test%\restAuthentication-test
call mvn clean
相关问题