Apache POI PPT - Installation



This chapter will guide you on how to prepare a development environment to start your work with Apache POI PPT. It will also teach you how to set up JDK on your machine before you set up Apache POI −

Setup Java Development Kit (JDK)

You can download the latest version of SDK from Oracle's Java site − Java SE Downloads. You will find instructions for installing JDK in downloaded files, follow the given instructions to install and configure the setup. Finally set PATH and JAVA_HOME environment variables to refer to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively.

If you are running Windows and have installed the JDK in C:\jdk-19, you would have to put the following line in your C:\autoexec.bat file.

set PATH=C:\jdk-19;%PATH% 
set JAVA_HOME=C:\jdk-19

Alternatively, on Windows NT/2000/XP, you will have to right-click on My Computer, select Properties → Advanced → Environment Variables. Then, you will have to update the PATH value and click the OK button.

On Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk-19 and you use the C shell, you will have to put the following into your .cshrc file.

setenv PATH /usr/local/jdk-19/bin:$PATH 
setenv JAVA_HOME /usr/local/jdk-19

Alternatively, if you use an Integrated Development Environment (IDE) like Borland JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio, you will have to compile and run a simple program to confirm that the IDE knows where you have installed Java. Otherwise, you will have to carry out a proper setup as given in the document of the IDE.

Popular Java Editors

To write your Java programs, you need a text editor. There are many sophisticated IDEs available in the market. But for now, you can consider one of the following −

  • Notepad − On Windows machine, you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad.

  • Netbeans − It is a Java IDE that is open-source and free, which can be downloaded from www.netbeans.org/index.html.

  • Eclipse − It is also a Java IDE developed by the eclipse open-source community and can be downloaded from www.eclipse.org.

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.4.1\poi-5.4.1.jar;

C:\poi-bin-5.4.1\lib\commons-codec-1.18.0.jar;

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

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

C:\poi-bin-5.4.1\lib\commons-io-2.18.0.jar;

C:\poi-bin-5.4.1\lib\SparseBitSet-1.3.jar;

C:\poi-bin-5.4.1\lib\log4j-api-2.24.3.jar;

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

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

C:\poi-bin-5.4.1\ooxml-lib\xmlbeans-5.3.0.jar

C:\poi-bin-5.4.1\ooxml-lib\commons-compress-1.27.1.jar

C:\poi-bin-5.4.1\ooxml-lib\curvesapi-1.08.jar

C:\poi-bin-5.4.1\ooxml-lib\commons-lang3-3.16.0.jar

2

Linux

Export CLASSPATH = $CLASSPATH:

/usr/share/poi-bin-5.4.1/poi-5.4.1.jar;

/usr/share/poi-bin-5.4.1/lib/commons-codec-1.18.0.jar;

/usr/share/poi-bin-5.4.1/lib/commons-collections4-4.4.jar;

/usr/share/poi-bin-5.4.1/lib/commons-math3-3.6.1.jar;

/usr/share/poi-bin-5.4.1/lib/commons-io-2.18.0.jar;

/usr/share/poi-bin-5.4.1/lib/SparseBitSet-1.3.jar;

/usr/share/poi-bin-5.4.1/lib/log4j-api-2.24.3.jar;

/usr/share/poi-bin-5.4.1/poi-ooxml-5.4.1.jar;

/usr/share/poi-bin-5.4.1/poi-ooxml-full-5.4.1.jar;

/usr/share/poi-bin-5.4.1/ooxml-lib/xmlbeans-5.3.0.jar

/usr/share/poi-bin-5.4.1/ooxml-lib/commons-compress-1.27.1.jar

/usr/share/poi-bin-5.4.1/ooxml-lib/curvesapi-1.08.jar

/usr/share/poi-bin-5.4.1/ooxml-lib/commons-lang3-3.16.0.jar

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>19</source>
               <target>19</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.4.1</version>
      </dependency>
      <dependency>
         <groupId>org.apache.poi</groupId>
         <artifactId>poi-ooxml</artifactId>
         <version>5.4.1</version>
      </dependency>    
   </dependencies>
</project>
Advertisements