”;
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
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) |
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) |
-
We assume the readers of this tutorial have Java SDK version 11.0.11 installed on their system.
-
In case you do not have Java SDK, download its current version from www.oracle.com/technetwork/java/javase/downloads/index.html and have it installed.
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:ProgramFilesjavajdk11.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 FilesJavajdk11.0.11bin” 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.0poi-5.1.0.jar;
C:poi-bin-5.1.0poi-ooxml-5.1.0.jar;
C:poi-bin-5.1.0poi-ooxml-full-5.1.0.jar;
C:poi-bin-5.1.0libcommons-codec-1.15.jar;
C:poi-bin-5.1.0libcommons-collections4-4.4.jar;
C:poi-bin-5.1.0libcommons-io-2.11.0.jar;
C:poi-bin-5.1.0libcommons-math3-3.6.1.jar;
C:poi-bin-5.1.0liblog4j-api-2.14.1.jar;
C:poi-bin-5.1.0libSparseBitSet-1.2.jar;
Cpoi-bin-5.1.0ooxml-libcommons-compress-1.21.jar
Cpoi-bin-5.1.0ooxml-libcommons-logging-1.2.jar
Cpoi-bin-5.1.0ooxml-libcurvesapi-1.06.jar
Cpoi-bin-5.1.0ooxml-libslf4j-api-1.7.32.jar
Cpoi-bin-5.1.0ooxml-libxmlbeans-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:
|
pom.xml
Following is the pom.xml file to run the programs in this tutorial.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>ApachePoiPPT</groupId> <artifactId>ApachePoiPPT</artifactId> <version>0.0.1-SNAPSHOT</version> <build> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>11</source> <target>11</target> <compilerArgs> <arg>--add-modules</arg> <arg>java.se,java.desktop</arg> </compilerArgs> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>5.1.0</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>5.1.0</version> </dependency> </dependencies> </project>
”;