Generate Fat Jar / Uber Jar from Source Code

A fat jar or an uber jar is a jar file which contains all of its dependencies. Therefore you don’t need to download external dependencies while running the jar file.

  1. Install OpenJDK 8
  2. Install GIT version control system
  3. Install Maven
  4. Clone the repository and create the api jar file using maven install

 

Step 1 : Install OpenJDK 8

Our API Runs on Java therefore we need JDK on our machine. We can install Oracle JDK also. But we recommend you to install OpenJDK-8 the open-source version because by using Oracle JDK you might get trapped into licensing issues.

To stay on the safe side of licensing issues prefer to install the open source version.

To install OpenJDK 8

Type these commands on your terminal

sudo apt-get udpate
sudo apt-get install openjdk-8-jdk

in order to verify jdk has been installed type type “java -version”

java -version

The above command gives the following output which indicates that Java 8 has been installed

openjdk version “1.8.0_151”
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

 

 

Step 2 : Install GIT Version Control System

Nearby Shops API is hosted on Github and we will be cloning a repository from Github. For cloning the repo we will require GIT. Therefore if GIT is not on your system. Please install GIT.

 

Step 3 : Install Maven
Maven is a build System for Java. It assembles the source code and generates the Executable Jar file.
We are going to generate an Executable Jar file from the latest Source code therefore we will require Maven also.
To install maven type the following

sudo apt-get update	 	 
sudo apt-get install maven

To verify that maven has been installed type

mvn -version

This will give the following / or similar output on your terminal which verifies that maven is installed.
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: “linux”, version: “4.4.0-112-generic”, arch: “amd64”, family: “unix”

 

Step 4 : Clone the Repository and Create the API Jar File
We will create a folder inside a home folder.
Go into your home directory

cd /	 	 
mkdir nearbyshops	 	 
cd nearbyshops

Head over to the github and get the repository link for cloning the repo.
Now clone the repository by typing

git clone https://github.com/SumeetMoray/Nearby-Shops-API-New.git	 	 

CD inside the cloned repository folder. ( See below for commands)
When you type “ls” on your command line inside the cloned repository folder. You will see various files and folders.

root:/nearbyshops# ls	 	 
Nearby-Shops-API	 	 
root:/nearbyshops# cd Nearby-Shops-API	 	 

root:/nearbyshops/Nearby-Shops-API# ls	 	 
keystore.jks LICENSE pom.xml README.md src target nearbyShopsAPI.iml

When you are inside the “Nearby-Shops-API” directory which contains the pom.xml file. You can now type the following commands to generate the jar file

cd /nearbyshops/Nearby-Shops-API	 	 
mvn install	 	 

maven looks for a pom.xml file in order to generate the Jar file.
When you run the mvn install it is going to take at least 5 minutes because maven will download all the dependencies. So keep patience.
“mvn install” command downloads all the dependencies and generates the fat jar (uber jar). The fat jar is a jar which is self contained and does not need to download any repositories to run.
after all the process is complete you can find the jar file generated inside the “target” folder.