0

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 ../../..
  )
)

1 Answer 1

1

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 ..
  )
)
Sign up to request clarification or add additional context in comments.

1 Comment

I tried it, and after a slight modification it works. what I changed: cd %%p to cd workspace/%%p and cd .. to cd ../.. however I have updated the OP with another question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.