Overview

In this blog, we will cover how to use maven without Admin access through cmd on Windows OS 10 & older versions.

Prerequisites

  • JAVA is installed (check C:\Program Files\Java\)
  • Apache Maven zip

Download Apache Maven directly from here or choose the latest zip file from here.

For Windows 10

For Windows 10 users, user can update Environment Variable for logged in Account, which doesn’t requires Admin access. Search for “Edit Environment variables for your Account” in windows search bar and add following properties

MAVEN_HOME=C:\Users\loggedinuser\Documents\apache-maven-3.6.3
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_202

For Other Windows version

env.bat

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.

cmd shortcut

Create a shortcut of cmd on Desktop

Steps:

  • 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)

Verify

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"

Conclusion

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.

Categories: MAVEN

1 Comment

Ruben · November 29, 2023 at 8:32 pm

Very usefull

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *