Working on multiple different projects have made me realize how important it is to always have the environment/set-up ready to start the work. I have seen GET's and even experienced people who have newly joined a company face issues in setting up a maven environment.
When I had started my career and was asked to get my maven environment set-up to start working, it was simple one click process as the company already had a tool of its own to set-up the work environment in just one click. The real struggle happened when I did switch the company and this time there was no specific tool provided to do the process.
I then had to go through specific websites and do the process explained there.
Here in this blog, I'll explain the process and provide the URLs for downloading the required tools to set up maven environment.
It's recommended to check with your companies internal tech support team first to know if there is any tool available that helps in downloading and setting up the maven environment automatically. There usually is a software center which provides tools to download and use, check with the tech support team if anything similar to a software center exist. In my case, the software center existed and it had jdk.
If a tool is available to set up the environment automatically, then no need to further read this blog, your environment will be set up properly. If an automated process is not available and only tools are available to be downloaded then follow the blog to understand which are all the configurations required to set up the maven environment.
Install Java
To install java, you can visit the official page of oracle and put in your credentails and download the required version of java.Once java is installed, run the following command to see if java is properly installed(I currently have OpenJDK 1.8 installed on my system
C:\Users\abc>java -version |
Check if the environment variable is set.
C:\Users\abc>echo %JAVA_HOME% %JAVA_HOME% |
If the environment variable JAVA_HOME is not set, follow the steps Create And Modify Environment Variables on Windows and create a new variable under System variables.
To confirm if the environment variable is set, open a new shell and run the following command:
C:\Users\abc>echo
%JAVA_HOME% C:\Program
Files\OpenJDK\jdk-8.0.292.10-hotspot |
Install Maven
- Download apache maven zip file from the official Apache Maven Project site.
- Unzip the file using your preferred archive extraction tool.
- Add the bin directory of apache-maven to the PATH environment variable under System variables by following the steps Create and Modify Environment Variables on Windows.
In my case, I had moved the extracted apache-maven directory to C:\apache-maven-3.5.4
Note: Run the following command using the administrative command prompt.
C:\Users\abc>echo
%PATH% C:\Program
Files\OpenJDK\jdk-8.0.292.10-hotspot\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program
Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\abc\AppData\Local\Microsoft\WindowsApps;C:\apache-maven-3.5.4\bin;C:\Program
Files\MySQL\MySQL Shell
8.0\bin\;C:\Users\abc\AppData\Local\Microsoft\WindowsApps; |
To confirm if maven is properly installed and configured, open a new shell and run the following command:
C:\Users\abc>mvn
-v Apache
Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe;
2018-06-18T00:03:14+05:30) Maven
home: C:\apache-maven-3.5.4\bin\.. Java
version: 1.8.0-292, vendor: OpenLogic-OpenJDK, runtime: C:\Program
Files\OpenJDK\jdk-8.0.292.10-hotspot\jre Default
locale: en_US, platform encoding: Cp1252 OS
name: "windows 10", version: "10.0", arch:
"amd64", family: "windows" |
Note: Restart pc/laptop once the above configuration for both java and maven is done.
Settings.xml
Each project has a settings.xml file created which mainly contains local repository, alternative remote repository servers, and authentication information.
Check with your colleagues and get the project-specific settings.xml file. You will have to update the settings.xml file and give your details for authentication. Once you get the file, move it to ${user.home}/.m2/settings.xml location. To know more about the settings.xml file, visit Apache Maven Project - Settings Reference.
Once this is done, run the maven build command in a cloned git repo to see if maven builds properly.
C:\Users\abc>mvn
clean install [INFO]
Scanning for projects... |
Conclusion
Java is required to be installed and properly configured on the system for maven to install. Maven installation is a simple process and mainly involves unzipping the file and setting up the required environment variable.
References
OpenLogic - OpenJDK downloadApache Maven Project - Installing Apache Maven
Apache Maven - Download Apache Maven Latest
1 Comments
good information
ReplyDelete