- 这里就不介绍nexus的搭建了;网上很多都是.sh脚本,linux比较合适,当然用git也可以运行;但是.bat文件肯定是所有windows系统都是可以执行的;所以这里介绍一下用windows的批处理命令来编写;
- 首先,你得先确定的仓库状态是处于Allow redeploy状态;
- 新建一个文件
mavenimport.bat
,用记事本打开后,把这些命令加入:- `@echo off
REM copy and run this script to the root of the repository directory containing files
REM this script attempts to exclude uploading itself explicitly so the script name is important
- `@echo off
REM Get command line params
set REPO_URL=
set USERNAME=
set PASSWORD=
:parseArgs
if "%~1""" goto endParseArgs
if "%~1""-r" (
set REPO_URL=%~2
shift
shift
goto parseArgs
)
if "%~1""-u" (
set USERNAME=%~2
shift
shift
goto parseArgs
)
if "%~1""-p" (
set PASSWORD=%~2
shift
shift
goto parseArgs
)
shift
goto parseArgs
:endParseArgs
REM Ensure REPO_URL ends with a slash
if not "%REPO_URL:~-1%"=="/" set REPO_URL=%REPO_URL%/
REM Get the current working directory (root directory where the script is executed)
set "SCRIPT_DIR=%cd%"
REM Find and upload files
for /r %%F in (*) do (
REM Exclude specific files and invalid paths like _remote.repositories
echo %%F | findstr /i /v "mavenimport.bat .git archetype-catalog.xml maven-metadata-local.xml maven-metadata-deployment.xml _remote.repositories" >nul
if not errorlevel 1 (
REM Get the absolute file path
set "FILE_PATH=%%F"
setlocal enabledelayedexpansion
REM Remove the script's root directory from the file path to get the relative pathset "RELATIVE_PATH=!FILE_PATH:%SCRIPT_DIR%\=!"REM Replace backslashes with slashes for URL compatibilityset "RELATIVE_PATH=!RELATIVE_PATH:\=/!"REM Upload the file using curlcurl -u "%USERNAME%:%PASSWORD%" -X PUT -v -T "%%F" "%REPO_URL%!RELATIVE_PATH!"endlocal
)
)`
- 运行:
mavenimport.bat -u 用户名 -p 密码 -r 仓库的url
这里替换成自己的就可以了; - 下面是详细解释,说一下比较关键的地方,感兴趣的可以看看:
- ``
----- 待完善 -----