OWL API: Setting up your development environment (IDE)

We know from experience that many people struggle with setting up their IDE of choice to develop ontology-based applications using the OWL API. Many developers, especially here at Manchester, like to use Eclipse for developing Java-based software, so we stick to it for the sake of convenience. The default bundle for Java developers also comes with Maven pre-installed, which we will use to manage our application development life-cycle. We highly recommend using Maven, or something comparable, to manage the often complex dependencies of software involving the OWL API. However, if you prefer to use your own IDE, many of the pitfalls we mention and tips we give in the following are applicable to all environments. We assume that you have the latest Java 8 Development Kit (JDK) installed on your system. After opening your Eclipse workspace of choice, we start by creating a simple Maven project.

  1. Create new Maven project (File->New->Other->Maven Project). Do not check the option ‘Create simple project’, check ‘Use default Workspace location’. Click ‘Next’.
  2. Select the quickstart archetype in the list (should be default), and click next.
  3. Enter Group Id ‘owl.cs’ and Artifact Id ‘myfirst.owlapi’; click ‘Finish’.
  4. In the newly created project, double-click on the pom.xml, and then click on the little tab at the bottom of the main window called ‘pom.xml’.
    Locate <properties>..</properties>, and inject right AFTER it (not in-between!) the snippet you can find in the infobox below.
  5. Save the pom file.

Eclipse will provide content assist here – pressing Ctrl-space will propose the tags to insert. Also, the dependency can be added in the Dependencies tab – the UI will guide you and create the XML tags for you.

An alternative way to get the dependency tags for any library is to search for them on http://search.maven.org – this is the Maven Central repository, where a large number of Java libraries is hosted. Once you locate the library and version you are after, the XML fragment required is displayed on the page.

Pay attention to the group id – for OWLAPI, the main libraries all have net.sourceforge.owlapi as their group id.

Insert the following XML snippet just after <properties></properties>. In case you already have the <dependencies> element, copy only the <dependency> elements that are necessary:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>5.1.4</version>
</dependency>
</dependencies>

You can check here for newer versions of the OWL API. To make sure everything worked out, perform the following task.

Running your first OWL API program

  1. Add the 4 lines of Java code in the info-box below to the main method of your App class (you will find the default App class underneath src/main/java in your project tree, inside your default package).
  2. Right-click on the pom.xml in the package explorer and click Run as–>Maven build. In the upcoming dialogue, set “install” as a goal and click “Run”. You should see Maven downloading a number of dependencies of the OWL API. Note that you have to be connected to the internet in order for this to work.
  3. Hover over the red underlined class names and select the first quick fix (“Import…”).
  4. In Eclipse, click on the little black downwards arrow next to the icon that looks like a green circle with a white arrow inside, select Run As->Java Application to execute your program.
//Create OWLOntologyManager
public static void main(String[] args) {
  OWLOntologyManager man = OWLManager.createOWLOntologyManager();
  System.out.println(man.getOntologies().size());
}

Your Eclipse console should show:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See ... for further details.
0

Do not worry about the warnings for now. The warning relates to the OWL API internal logging mechanism and will not affect your program.

Congratulations! You have successfully set up your IDE for OWL API development! In the next chapter, we will learn how to manage ontologies with the OWLOntologyManager and introduce you to some of the most fundamental concepts of the API.

Be the first to comment

Leave a Reply

Your email address will not be published.


*