我创建了一个.bat文件,内容如下:
mvn clean; mvn package;但是它并没有起作用,只有第一条命令被执行了。请问有人能帮我吗?
mvn clean; mvn package;但是它并没有起作用,只有第一条命令被执行了。请问有人能帮我吗?
使用
call mvn clean
call mvn package
请注意,在批处理文件中您不需要分号。而您需要使用call
的原因是mvn
本身就是一个批处理文件,批处理文件需要使用call
互相调用,否则控制权不会返回给调用者。call mvn
完成后进行echo on
(在下一行上)。这是因为mvn
关闭了回显并没有将其打开。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
你也可以使用以下一行代码:
call mvn clean package
call
命令,这样在 mvn
命令后输入的任何内容都会被执行。 - Joey观察到的行为源自 MS-DOS 1.0 的时代,并因兼容性原因而保留。作为解决方案,您应以以下方式使用 Windows call 函数:
call mvn clean
call mvn package
“Call”命令可以从一个批处理程序中调用另一个批处理程序,并将其解释为子程序。
我有更多的项目要运行,我创建了这样一个批处理文件:
@echo off
SET DEVELOPMENT_HOME=C:\Projects
cd %DEVELOPMENT_HOME%\Project1\
call mvn clean install
cd %DEVELOPMENT_HOME%\Project2\
call mvn clean install
当你想在父文件中调用另一个批处理文件时,请使用“call”命令,这样控制权将返回到父批处理文件并继续执行。
例如:call mvn clean install
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.
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%
使用
执行 mvn clean package
命令
sample
------
echo %test%
cd %test%\ManaulActionAddNotes-test
call mvn clean
cd %test%\restAuthentication-test
call mvn clean
-B
或--batch-mode
,用于“以非交互(批处理)模式运行(禁用输出颜色)”。 - Liscare