Skip to content

Instantly share code, notes, and snippets.

@jamezrin
Last active November 11, 2016 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamezrin/618106523ef2a52feaf7 to your computer and use it in GitHub Desktop.
Save jamezrin/618106523ef2a52feaf7 to your computer and use it in GitHub Desktop.
Little script to install maven to your system easily
@echo off
title Easy Maven Installer Script
if defined M2_HOME (
choice /m "Maven seems to be already installed, do you want to continue?" /c YN
if errorlevel 2 (
echo The installation has been cancelled
pause
exit
) else if errorlevel 1 (
echo Continuing with the installation...
)
echo.
)
:checkadmin
net file 1>nul 2>nul
if '%errorlevel%' == '0' (
goto proceed
) else (
powershell "saps -filepath %0 -verb runas" >nul 2>&1
)
exit /b
echo.
:proceed
color 02
echo Little script to install maven to your system easily
echo There are some variables inside the script that you might want to modify
echo.
timeout 3 /nobreak >nul
:: Modify this variables to your liking
set VERSION=3.3.9
set MIRROR=http://www-eu.apache.org/dist/
:: Modify the URL variable if your mirror folder structure is different
set URL=%MIRROR%/maven/maven-3/%VERSION%/binaries/apache-maven-%VERSION%-bin.zip
:: Modify this variables to the place you want maven to be installed on
set PARENT=%ProgramW6432%\Apache Maven Project\
set FOLDER=%PARENT%apache-maven-%VERSION%
set ZIP=%~dp0\maven-%VERSION%.zip
if exist %ZIP% (
goto unzip
) else (
goto download
)
echo.
:download
echo Downloading the binaries from %URL%...
powershell -Command "wget %URL% -UseBasicParsing -OutFile %ZIP%"
echo.
:unzip
echo Unziping the binaries to %FOLDER%...
powershell -Command "Expand-Archive -Force %ZIP% ""%PARENT%"""
echo.
:setvars
echo Setting the necessary variables...
setx /m M2_HOME "%FOLDER%"
setx /m M2 "%FOLDER%\bin"
setx /m PATH "%PATH%;%FOLDER%\bin"
echo.
if defined JAVA_HOME (
echo The program has now finished, you can should be able to run maven without problems
) else (
echo The program has now finished, but there are some problems that you should fix before trying to run maven
echo WARNING: JAVA_HOME is not defined in your system and maven needs it, define it with the value of your Java Development Kit installation folder (example: C:\Program Files\Java\jdk1.8.0_73)
)
pause
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment