腳本地址: https://github.com/jayknoxqu/configuration/blob/master/maven/script
原因
使用maven下載項(xiàng)目依賴的jar包時(shí)状植,很容易因?yàn)楦鞣N原因(網(wǎng)速慢、斷網(wǎng))導(dǎo)致jar包下載失敗,出現(xiàn)很多xxx.jar.lastUpdated的文件,無(wú)法正常啟動(dòng)項(xiàng)目,需要及時(shí)清理务豺。
腳本
Windows
執(zhí)行cleanLastUpdated.bat ~/.m2/repository
,其中"~/.m2/repository"目錄為Maven本地倉(cāng)庫(kù)路徑
@echo off
set REPOSITORY_PATH=%1
if "%REPOSITORY_PATH%" == "" (
echo "Usage: %0 <maven_repository_path>"
echo "Example: %0 ~/.m2/repository"
echo "Explain: "~" is your profile's home directory"
echo.
echo.
echo "press enter to quit!" & pause > nul
goto :eof
)
echo.
echo "Began clean lastUpdated file"
echo.
for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (
del /s /q %%i
)
echo.
echo "End clean lastUpdated file."
echo.
echo.
echo "press enter to exit!" & pause > nul
exit
Linux
執(zhí)行./cleanLastUpdated.sh ~/.m2/repository
,其中"~/.m2/repository"目錄為Maven本地倉(cāng)庫(kù)路徑
#!/bin/bash
REPOSITORY_PATH=$1
if [ "$REPOSITORY_PATH" = "" ]; then
echo "Usage: $0 <maven_repository_path>"
echo "Example: $0 ~/.m2/repository"
echo "Explain: "~" is your profile's home directory"
exit 1
fi
echo "Began clean lastUpdated file"
for f in `find $REPOSITORY_PATH -name "*lastUpdated*"`
do
echo $f & rm $f
done
echo "End clean lastUpdated file."