Question

I would like to create a windows batch file "compile.bat" that loops through all subfolders inside "workspace" exept for the folter ".metadata", and execute "mvn clean install" in there. I would also like it to find the file with the ".jar" extension (the only file in the map "target" inside that folder) and force copy it to a fixed directory. so if my map structure is like this:

-eclipse
-maven
-some other folders and files
-compile.bat
-workspace
  -.metadata
  -someFolder
   -target
    -randomFolders
    *someName.jar
  -someOtherFolder
   -target
    -moreRandomFolders
    *someOtherName.jar

it would have to do:

cd workspace
cd someFolder
mvn clean install
::copy someName.jar to fixed map
cd ..
cd someOtherFolder
mvn clean install
::copy someNameOther.jar to fixed map
cd ..

How to do this?

EDIT: here's what I ended up using:

for /F %%p in ('dir /ad /b workspace') do (
  echo.%%p | findstr /I "metadata" 1>nul
  if errorlevel 1 (
    echo Whatever, I can do what I want %%p
    cd workspace/%%p
    mvn clean install
    cd target
    for /r %%i in (*.jar) do (
      echo %%i
      copy "%%i" "../../../CraftBukkit/target/plugins" /Y
    )
    cd ../../..
  )
)
Was it helpful?

Solution

Please try the following code:

for /F %%p in ('dir /ad /b workspace') do (
  echo.%%p | findstr /I "metadata" 1>nul
  if errorlevel 1 (
    echo Whatever, I can do what I want %%p
    cd %%p
    mvn clean install
    cd ..
  )
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top