Apache Jena Installation & Configuration
Using Jena with Apache Maven
Apache Maven is a tool to help Java projects manage their dependencies on library code, such as Jena. By declaring a dependency on the core of Jena in your project’s pom.xml
file, you will get the consistent set of library files that Jena depends on, automatically added too.
Prerequisites:
- Maven Installed: Make sure Maven is installed on your computer. If not, please follow Maven installation instructions.
- IDE Installed: Install an IDE of your choice. This guide assumes you are using Eclipse.
Steps for Using Apache Jena with Maven in Eclipse:
-
Open Eclipse:
Launch Eclipse and select your workspace directory. -
Install Maven Integration for Eclipse:
If not already installed:- Go to
Help > Eclipse Marketplace...
- Search for “Maven Integration for Eclipse” or “m2e”.
- Install it if it’s not already installed.
- Go to
-
Create a New Maven Project:
- Go to
File > New > Project...
- Select
Maven > Maven Project
and click Next. - Choose a workspace location or use the default and click Next.
- Go to
-
Select an Archetype:
- Select
maven-archetype-quickstart
(or another archetype if you prefer) and click Next. - Enter your
Group ID
(e.g.,com.example
),Artifact ID
(e.g.,jena-example
), andVersion
(e.g.,1.0-SNAPSHOT
). - Click Finish.
- Select
-
Add Apache Jena Dependencies:
- Right-click on the newly created project in the Project Explorer.
- Select
Properties > Java Build Path > Libraries > Add Maven Dependency...
. - This will open the
pom.xml
file. - Add the Apache Jena dependencies inside the
<dependencies>
section ofpom.xml
.
Here’s how to specify a dependency on a version of Jena:
-
Create Your Java Class:
- In the
src/main/java
directory, create a new Java class (e.g.,JenaExample.java
). - Add your Java code using Apache Jena.
- In the
-
Run Your Project:
- Right-click on your project and select
Run As > Java Application
.
- Right-click on your project and select