Installing External Jars to Local Maven Repository

Reading Time: 1 minute

Central Maven repository has a large variety of libraries however there are times that we may be in need of installing such 3rd party jars that are not offered in the central in mavenized projects. This command will allow you to install such jars to your local M2 folder. You need to make sure that if multiple developers are working on the project that experiences this situation, the participants must also carry out the same procedure.

The Command

[bash lang=”bash” smarttabs=”true” tabsize=”4″ wraplines=”true”]mvn install:install-file -Dfile={FILELOCATION}
-Dversion=VERSION -Dpackaging=PACKAGINGTYLE[/bash]

Example Command

[bash smarttabs=”true” tabsize=”4″ wraplines=”true”]mvn install:install-file -Dfile=C:\myjar1-0.jar
-DgroupId=com.tugrulaslan -DartifactId=MyJar
-Dversion=1.0 -Dpackaging=jar[/bash]

Usage in pom.xml


External Links

Passing the selected maven profile/value to java

Reading Time: 1 minute

in this post we will pass the selected env value to the java file.  when you start the project as follows:




java file

private Properties props = new Properties();
String selectedPaymentProfile = System.getProperty("env");
		final String fileName = selectedPaymentProfile.concat(".properties");
		try {
			props.load(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(paymentProperties)));
			URI = props.getProperty("URI");
		} catch (FileNotFoundException e) {
			logger.error("Exception in providerDetails: " + e);
		} catch (IOException e) {
			logger.error("Exception in providerDetails: " + e);



One jar with all dependencies

Reading Time: 1 minute

The configuration is below when you issue this command “mvn clean package assembly:single” then you will get a jar file containing all the sources and if  you check the me MANIFEST.MF file and you will see the line “Main-Class: com.tugrulaslan.App” the value we set below in the pom.xml

<project xmlns="" xmlns:xsi=""





Excluding jar/subdependency from a main dependency from a maven project

Reading Time: 1 minute

In my project at work, the front end java framework ZKoss I use at work, pulls servlet api jar on its own since its dependency is required for the jar, it was mismatching one i was using. So I had to exclude the jar from zkoss dependency

the below is the ZK’s required jar and I am excluding servlet-api from the dependency and pulling the servlet-api upon my request.

<!-- ZK Spring dependencies servlet-api being excluded-->

<!--This is the one I am pulling from maven's repo -->

Adding external jars to the local maven repository

Reading Time: 1 minute

At work I faced a situation that I had to add external jar libraries into my maven project, since most of required Java packages offered by Maven the automation, I have come across with the situation that Business objects external jars needed to be imported into the project. So I have done a small research regarding the issue, here is the outcome. First of all keep all he required in an easy location. I put the files in a folder called “libs” located right underneath C root drive the command below will do the magic

C:\workspace\CMC_REPORTING>mvn install:install-file -Dfile={FILELOCATION} -DgroupId={GROUP/DOMAINNAME} -DartifactId={FILENAME} -Dversion={VERSION} -Dpackagi

This command is going to add the required file to your local maven repo and you will get to use it, sample output after you carry out this command is:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\lib>mvn install:install-file -Dfile=fedmaster.jar -Dartifac
tId=fedmaster -Dversion=1.0 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom
[INFO] Installing C:\lib\fedmaster.jar to C:\Users\akn522a\.m2\repository\com\sa
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.365s
[INFO] Finished at: Mon Jan 20 09:21:16 EET 2014
[INFO] Final Memory: 2M/15M
[INFO] ------------------------------------------------------------------------

After the screen the necessary .jar file has been successfully imported into our maven local repo. There is one point left needs to be done, adding the imported jar in our pom.xml file. As usual add the line to your pom.xml


This is all now deploy your project to your application server and give it a shot

Installing Maven on Linux, Windows and Mac

Reading Time: 3 minutes


This post will show you to install and configure maven on Windows, Linux and Mac. Before performing the installation, make sure the Java Development Kit is properly installed and configured. For Linux you can refer to my post


For this installation I have performed the task on Ubuntu 18.06 LTS 64 bit, but also referred the same for other distros, it all turned out to be working perfectly. You can use the manual way to perform installation on other distros. For this make sure the java

Installing using the Package Manager

sudo apt-get install maven

Installing Manually

Navigate to Apache Maven’s official web site and and download the latest version (3.5.4 as of writing this article) the binary tar.gz package.

1. Unpack the Tar file

tar zxvf apache-maven-3.5.4-bin.tar.gz 

2. Move the folder to the opt folder

sudo mv apache-maven-3.5.4 /opt/

3.Create a Maven profile file

sudo nano /etc/profile.d/

3.1. Add these lines in the “.sh” file

export M2_HOME=/opt/apache-maven-3.5.4
export M2=$M2_HOME/bin 

4. Reload the “sh” file in the system

source /etc/profile.d/
. /etc/profile.d/

5. Check the Maven installation

mvn --version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Maven home: /opt/apache-maven-3.5.4
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_181/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-23-generic", arch: "amd64", family: "unix"


Download the binary file in .zip or tar.gz does not matter extract the folder under C drive if you want you may create the folder wherever you want, but to make it easier you shall consider practical way of it, after you extract the folder

Right Click Computer and click on Properties


On the left side of the properties, click on Advanced system settings


Below click on Environment Variables


Click on “New” on Users variables and enter the details as below


and on system variables find PATH and add the line


and now lets launch command line and see if its configured


Mac OS

Normally maven comes out of package on mac os operating systems since 10.6.8 Snow Leopard, test if the maven is installed on your mac launch terminal and enter the command:

mvn -version
Apache Maven 3.0.3 (r1075438; 2011-02-28 19:31:09+0200)
Maven home: /usr/share/maven
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.5", arch: "x86_64", family: "mac"
Tugruls-Mac:~ tugrulaslan$

to install it manually as the above linux package file download and exract the file the same way

tar -zxvf apache-maven-3.1.1-bin.tar.gz
sudo mv apache-maven-3.1.1 /usr/lib/maven
vim ~/.bash_profile

and these lines

export M2_HOME=/usr/lib/maven
export PATH=$PATH:$M2_HOME/bin

before you proceed the maven installation, please make sure that you have successfully carried out jre and jdk installation and configuration

Maven goals

Reading Time: 1 minute
  • validate – validate the project is correct and all necessary information is available
  • compile – compile the source code of the project
  • test – test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package – take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test – process and deploy the package if necessary into an environment where integration tests can be run
  • verify – run any checks to verify the package is valid and meets quality criteria
  • install – install the package into the local repository, for use as a dependency in other projects locally
  • deploy – done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

Creating a Maven web application and integration for Eclipse and IntelliJ IDEs

Reading Time: 1 minute

Hi folk

In this tutorial I will show you how you can create a dynamic web project using maven in command line. First of all if you would like to create a web app rapidly then issue the command below, or if you would like to create and browse different type of projects remove the project type and other specifications in the below given command. On Linux, Windows or Mac does not matter launch your terminal/command line app to create our project:

mvn archetype:generate -DgroupId=PROJECTPACKINGNAMEGOESHERE -DartifactId=PROJECTNAMEGOESHERE -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

As soon as you launch this code the outcome should look like this:


our project is ready and lets convert our project into an Eclipse or IntelliJ project issue the command below but first of all navigate to the project folder first otherwise you will have the errors maven unable to locate the pom.xml file:

Eclipse Integration

mvn eclipse:eclipse -Dwtpversion=2.0

IntelliJ Integration

mvn idea:idea -Dwtpversion=2.0

After the command our project will look and converted to that IDE structure, the below the folder structure since I am an IntelliJ fan the here is my folder output:


Deploying Maven Projects to Tomcat

Reading Time: 2 minutes

In this tutorial I will show you how to easily deploy your project on your favorite. We have a few of code and file changes thats all. First of all lets start out with the pom file. We need maven tomcat plugin to deploy our war file, copy and paste the below code between build tags in your pom.xml file and edit it the way you want

    <!-- this maven plugin directly does deploy the project to tomcat7 -->
    <!-- also check out tomcat users and maven settings for the equality of credentials -->
    <!-- if credentials do not match maven will fail to deploy the project to AS -->
                  <!-- Refer to the server settings in your ~/.m2/settings.xml -->

We now need to alter our tomcat-users.xml file which is located under conf folder in your main tomcat file. Add the line below in your tomcat-users.xml file

 <role rolename="manager-gui"/>
 <role rolename="manager-script"/>
 <role rolename="manager-jmx"/>
 <role rolename="manager-status"/>
 <role rolename="admin-gui"/>
 <role rolename="admin-script"/>

 <user username="tomcat" password="password"  roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>

And now one more file left to be altered, settings.xml file once again located in conf folder in your main maven folder. Add this line between servers tag


We are all setup right now. To give you the advice if you are working on STS or Eclipse you will need to add m2e plugin from eclipse market to run the desired project with the goal

mvn clean tomcat7:deploy

If you redeploy it please do not forget to change the goal. If your favorite IDE is IntelliJ then it is still easy. Expand Maven Projects side on the right(If you cant find it navigate to View > Tool Buttons) and go to Plugins expand tomcat7 and click on tomcat7:deploy

After these settings navigate to your serverpath/projectname to see all works.