Hello Guys,
We have seen Introduction of Apache POI in previous post. In this post we will see below topics:
- Integration of apache POI libraries using Direct download
- Integration of apache POI libraries using Build automation tool Maven
- 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 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:
- Right click on Java project and navigate to Build Path – > Configure Build Path.
- Click on “Libraries” tab.
- Click on “Add External JARS…”.
- Navigate to location of Apache POI jars and select.
- Click on Apply and close button.
- 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:
- We need to manually update the jar to latest versions.
- If we keep required jar files within project, it will increase project size and difficult to share with others.
- If we add as external jars, people need to download and add jar files to project in new system.
- 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:
- Create a maven java project.
- Navigate to Maven Central Repository.
- Search for “Apache POI”.
- 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