OpenNLP - Environment


In this chapter, we will discuss how you can setup OpenNLP environment in your system. Let’s start with the installation process.

Installing OpenNLP

Following are the steps to download Apache OpenNLP library in your system.

Step 1 − Open the homepage of Apache OpenNLP by clicking the following link −

Apache OpenNLP

Step 2 − Now, click on the Downloads link. On clicking, you will be directed to a page where you can find various mirrors which will redirect you to the Apache Software Foundation Distribution directory.

Step 3 − In this page you can find links to download various Apache distributions. Browse through them and find the OpenNLP distribution and click it.


Step 4 − On clicking, you will be redirected to the directory where you can see the index of the OpenNLP distribution, as shown below.

Index of Opennlp

Click on the latest version from the available distributions.

Step 5 − Each distribution provides Source and Binary files of OpenNLP library in various formats. Download the source and binary files, and (for Windows).

Source and Binary Files of OpenNLP

Setting the Classpath

After downloading the OpenNLP library, you need to set its path to the bin directory. Assume that you have downloaded the OpenNLP library to the E drive of your system.

Now, follow the steps that are given below −

Step 1 − Right-click on 'My Computer' and select 'Properties'.

Step 2 − Click on the 'Environment Variables' button under the 'Advanced' tab.

Step 3 − Select the path variable and click the Edit button, as shown in the following screenshot.

System Variables Path

Step 4 − In the Edit Environment Variable window, click the New button and add the path for OpenNLP directory E:\apache-opennlp-1.6.0\bin and click the OK button, as shown in the following screenshot.

Edit Environment Variable Window

Eclipse Installation

You can set the Eclipse environment for OpenNLP library, either by setting the Build path to the JAR files or by using pom.xml.

Setting Build Path to the JAR Files

Follow the steps given below to install OpenNLP in Eclipse −

Step 1 − Make sure that you have Eclipse environment installed in your system.

Step 2 − Open Eclipse. Click File → New → Open a new project, as shown below.

New Project

Step 3 − You will get the New Project wizard. In this wizard, select Java project and proceed by clicking the Next button.

Java Project

Step 4 − Next, you will get the New Java Project wizard. Here, you need to create a new project and click the Next button, as shown below.

My Project

Step 5 − After creating a new project, right-click on it, select Build Path and click Configure Build Path.

Configure Build Path

Step 6 − Next, you will get the Java Build Path wizard. Here, click the Add External JARs button, as shown below.

Java Build Path

Step 7 − Select the jar files opennlp-tools-1.6.0.jar and opennlp-uima-1.6.0.jar located in the lib folder of apache-opennlp-1.6.0 folder.

Opennlp Tools

On clicking the Open button in the above screen, the selected files will be added to your library.

Add External JARs

On clicking OK, you will successfully add the required JAR files to the current project and you can verify these added libraries by expanding the Referenced Libraries, as shown below.

Sample Workspace

Using pom.xml

Convert the project into a Maven project and add the following code to its pom.xml.

<project xmlns=""