In this blog, we will cover how to use maven without Admin access through cmd on Windows OS.
- JAVA is installed (check C:\Program Files\Java\)
- Apache Maven zip
Create a .bat file that will help to add MAVEN and JAVA path on cmd startup.
In your User’s Home dir (C:\Users\username) add env.bat file with below content
@echo off if "%MAVEN_HOME%"=="" ( echo Setting environment... ) else ( echo Environment already defined. exit /b ) set MAVEN_HOME=C:\Users\loggedinuser\Documents\apache-maven-3.6.3 set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_202 set path=%MAVEN_HOME%\bin;%path% set path=%JAVA_HOME%\bin;%path%
Note: Don’t forget to update MAVEN_HOME and JAVA_HOME Path based on your system setup
Our bat file is ready, we just need to link it to cmb on startup.
Create a shortcut of cmd on Desktop
- Goto C:\WINDOWS\system32/
- Select cmd => Right Click => Send To => Desktop
- cmd Shortcut will be created on your desktop
- Right-click newly created cmd Shortcut
- Select Properties from the menu (last option)
- A new window will pop up
- In target path append “-cmd /K env.bat”
- Sample Path should look like this (%windir%\system32\cmd.exe -cmd /K env.bat)
Open newly created cmd shortcut.
Run mvn -v should return like this
C:\Users\username>mvn -v Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T00:30:29+05:30) Maven home: C:\Users\username\Documents\apache-maven-3.6.1\bin\.. Java version: 1.8.0_202, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_202\jre Default locale: en_SG, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
We are instructing cmd to run env.bat each time we open cmd from the desktop so that we don’t have to set MAVEN and JAVA path each time.
Finally, we have successfully configured maven without Admin access.