OpenCV with Maven: Part 1 – Create your own Maven repo (w/o high-level bullshit)

Preface

The n. 1 most requested feature in the OpenCV issue tracker is „Package a maven version of Java bindings”. The issue was opened in June 2013 and nothing was done since then, which means they probably won’t provide the packaging in the foreseeable future. A truly retarded move, but it goes with the philosophy of being the shittiest library out there. Since OpenCV is essentially a set of native libraries with a bad java wrapper, integrating it into a java maven project can be quite tricky. Here I propose my solution I used for the OpenCV project I am currently working on. Though this tutorial takes OpenCV as an example, the steps can be used for repoing basically any native library / library not in a publicly available repository (central…).

In this first part we will go through the steps to create and configure your own maven repository. In the next part we will look at the actual native library hosting and integration.

Creature creation

Although many people don’t realize, maven is brilliantly simple. You do not need all that shiny software layers such as JFrog, Nexus and others to host your private repo. You probably already have everything you need on your webhosting:

  • HTTP webserver (Apache…)
  • FTP access

M2 repo is actually just a folder structure adhering to some predefined package-naming rules. Maven follows this folder structure to find all the artifacts. To create your own remote repository you need to:

  1. Create a folder for the repo on the http server (duh!), such as “maven2
  2. .htaccess that shit with directory listing, to make it traversable from your browser (no need for Nexus bloatware):
    Options +Indexes
  3. Copy desired artifacts from your local .m2 into the created folder via FTP, following the established paths. The structure closely duplicates the one found in your local .m2 folder. So the artifact:
    <dependency>
        <groupId>eu.dindoffer</groupId>
        <artifactId>jcommon</artifactId>
        <version>1.0.23</version>
    </dependency>

    would reside in /web/maven2/eu/dindoffer/jcommon/1.0.23/

  4. Specify your repo address in the maven project pom.xml:
    <repositories>
        <repository>
            <id>eu-dindoffer-m2</id>
            <name>my repo for fukin opencv</name>
            <url>http://dindoffer.eu/maven2/</url>
        </repository>
    </repositories>

    As an alternative you can edit the settings.xml in your .m2. However, defining the remote repo inside the project pom makes it easier to share the info with other people and is generally a quicker solution.

    In the next part we will integrate the native OpenCV libs into our project.

Leave a Reply