Integration of Apache POI Java Library in a Java Project – Direct Download & Using Maven or Gradle

Hello Guys,

We have seen Introduction of Apache POI in previous post. In this post we will see below topics:

  1. Integration of apache POI libraries using Direct download
  2. Integration of apache POI libraries using Build automation tool Maven
  3. Integration of apache POI libraries using Build automation tool Gradle ( This we will see in a separate post.)

 

Integration of apache POI libraries using Direct download:-

You can download Apache POI libraries from its official website. See the image below:

Apache POI

Apache POI provides both source files( .java files) and compiled files ( Binary files or .class files). You should download binary files. If you are using windows or mac machine, click on file with .zip extension under Binary Distribution. If you are using Linux operating system, click on file with extension .gz under Binary Distribution. Unzip it when it is done.

Apache POI bundles all components to read/write different Microsoft documents together. So you need to identify required one and use. You will see below jars after unzipping:

If you want to read write an excel, you need poi and poi-ooxml jars. You can see components map below from Apache POI official website:

Above jar files require some supportive jar files which you can find lib and ooxml-lib folders in unzipped files.

You can refer prerequisites here:

So, You need to add all required jar files to build path. If you are using eclipse, you can add as external libraries or add to build path.

Steps to add POI libraries as external jars:

  1. Right click on Java project and navigate to Build Path – > Configure Build Path.
  2. Click on “Libraries” tab.
  3. Click on “Add External JARS…”.
  4. Navigate to location of Apache POI jars and select.
  5. Click on Apply and close button.
  6. You can see POI jars are added to build path and listed in “Referenced Libraries” folder.

You are done. A lot of steps. There are some problems in this way:

  1. We need to manually update the jar to latest versions.
  2. If we keep required jar files within project, it will increase project size and difficult to share with others.
  3. If we add as external jars, people need to download and add jar files to project in new system.
  4. Change in location of jar files will also create problems.

Worried!! Don’t be. Solution is there. Maven or Gradle.

Integration of apache POI libraries using Build automation tool Maven:

This is the simplest way and solve all problems of maintaining jars manually. It will take care if you share project with anyone.

Step by step to integrate Apache POI libraries in a Java Maven Project:

  1. Create a maven java project.
  2. Navigate to Maven Central Repository.
  3. Search for “Apache POI”.
  4. You need to copy below dependencies:

a. poi

b. poi-ooxml

Click on Central tab and copy latest dependencies. Paste above dependencies in pom.xml of your maven project and save it. As soon as you save it, Maven will build workspace with apache poi dependencies.

pom.xml:


  4.0.0

  ApachePOI
  ApachePOI
  0.0.1-SNAPSHOT
  jar

  ApachePOI
  http://maven.apache.org

  
    UTF-8
  

  
    

    org.apache.poi
    poi-ooxml
    4.0.1



    org.apache.poi
    poi
    4.0.1


  


You can refer Maven Dependencies listed below in your maven project:

You are all set to use Apache POI libraries now. I tried to cover this simple topic in details as people are confused with which jar files to be used. Hope it will help you now.

In next post, we will explore more about it. Stay tuned.

In case of any doubt, suggestion or you find some mistake, feel free to let me know in comments.

#ThanksForReading

#DonateIfYouThinkMyPostsHelpYou

Leave a Reply

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