Apache POI Word - Installation



This chapter takes you through the process of setting up Apache POI on Windows and Linux based systems. Apache POI can be easily installed and integrated with your current Java environment following a few simple steps without any complex setup procedures. User administration is required while installation.

System Requirements

JDK Java SE 2 JDK 1.5 or above
Memory 1 GB RAM (recommended)
Disk Space No minimum requirement
Operating System Version Windows XP or above, Linux

Let us now proceed with the steps to install Apache POI.

Step 1: Verify your Java Installation

First of all, you need to have Java Software Development Kit (SDK) installed on your system. To verify this, execute any of the two commands depending on the platform you are working on.

If the Java installation has been done properly, then it will display the current version and specification of your Java installation. A sample output is given in the following table.

Platform Command Sample Output
Windows

Open command console and type −

\>java -version

java version "11.0.11" 2021-04-20 LTS

Java(TM) SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194)

Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode)

Linux

Open command terminal and type −

$java -version

java version "11.0.11" 2021-04-20 LTS

Open JDK Runtime Environment 18.9 (build 11.0.11+9-LTS-194)

Open JDK 64-Bit Server VM (build 11.0.11+9-LTS-194, mixed mode)

Step 2: Set your Java Environment

Set the environment variable JAVA_HOME to point to the base directory location where Java is installed on your machine. For example,

Sr.No. Platform & Description
1

Windows

Set JAVA_HOME to C:\ProgramFiles\java\jdk11.0.11

2

Linux

Export JAVA_HOME = /usr/local/java-current

Append the full path of Java compiler location to the System Path.

Sr.No. Platform & Description
1

Windows

Append the String "C:\Program Files\Java\jdk11.0.11\bin" to the end of the system variable PATH.

2

Linux

Export PATH = $PATH:$JAVA_HOME/bin/

Execute the command java -version from the command prompt as explained above.

Step 3: Install Apache POI Library

Download the latest version of Apache POI from https://poi.apache.org/download.html and unzip its contents to a folder from where the required libraries can be linked to your Java program. Let us assume the files are collected in a folder on C drive.

Add the complete path of the required jars as shown below to the CLASSPATH.

Sr.No. Platform & Description
1

Windows

Append the following strings to the end of the user variable

CLASSPATH −

C:\poi-bin-5.1.0\poi-5.1.0.jar;

C:\poi-bin-5.1.0\poi-ooxml-5.1.0.jar;

C:\poi-bin-5.1.0\poi-ooxml-full-5.1.0.jar;

C:\poi-bin-5.1.0\lib\commons-codec-1.15.jar;

C:\poi-bin-5.1.0\lib\commons-collections4-4.4.jar;

C:\poi-bin-5.1.0\lib\commons-io-2.11.0.jar;

C:\poi-bin-5.1.0\lib\commons-math3-3.6.1.jar;

C:\poi-bin-5.1.0\lib\log4j-api-2.14.1.jar;

C:\poi-bin-5.1.0\lib\SparseBitSet-1.2.jar;

C\poi-bin-5.1.0\ooxml-lib\commons-compress-1.21.jar

C\poi-bin-5.1.0\ooxml-lib\commons-logging-1.2.jar

C\poi-bin-5.1.0\ooxml-lib\curvesapi-1.06.jar

C\poi-bin-5.1.0\ooxml-lib\slf4j-api-1.7.32.jar

C\poi-bin-5.1.0\ooxml-lib\xmlbeans-5.0.2.jar

2

Linux

Export CLASSPATH = $CLASSPATH:

/usr/share/poi-bin-5.1.0/poi-5.1.0.jar.tar:

/usr/share/poi-bin-5.1.0/poi-ooxml-5.1.0.tar:

/usr/share/poi-bin-5.1.0/poi-ooxml-full-5.1.0.tar:

/usr/share/poi-bin-5.1.0/lib/commons-codec-1.15.jar.tar:

/usr/share/poi-bin-5.1.0/lib/commons-collections4-4.4.tar:

/usr/share/poi-bin-5.1.0/lib/commons-io-2.11.0.tar:

/usr/share/poi-bin-5.1.0/lib/commons-math3-3.6.1.tar:

/usr/share/poi-bin-5.1.0/lib/log4j-api-2.14.1.tar:

/usr/share/poi-bin-5.1.0/lib/SparseBitSet-1.2.tar:

/usr/share/poi-bin-5.1.0/ooxml-lib/commons-compress-1.21.tar:

/usr/share/poi-bin-5.1.0/ooxml-lib/commons-logging-1.2.tar:

/usr/share/poi-bin-5.1.0/ooxml-lib/curvesapi-1.06.tar:

/usr/share/poi-bin-5.1.0/ooxml-lib/slf4j-api-1.7.32.tar:

/usr/share/poi-bin-5.1.0/ooxml-lib/xmlbeans-5.0.2.tar:

Advertisements