mroeder
mroeder

Reputation: 43

How to include opencv in an intellij sub module (maven)

I'm using IntelliJ IDE with maven. I have a project (main module) with a parent pom, that includes 2 sub modules, each with their own pom.

<!-- main pom module part -->
<packaging>pom</packaging>
<modules>
    <module>ModuleA</module>
    <module>ModuleB</module>
</modules>

<!-- example for sub module pom -->
<parent>
    <artifactId>main-module</artifactId>
    <groupId>my.main.module</groupId>
    <version>0.5.0</version>
</parent>

Image ModuleA includes the OpenCV Java wrapper and ModuleB is an executable java program (having the main class) using ModuleA.

The compiling works fine, but when I run ModuleB with having set the library path in the launcher, I'll get the following error for ModuleA:

java.lang.NoClassDefFoundError: org/opencv/core/Core

Any suggestions how to fix this?

Upvotes: 1

Views: 1017

Answers (2)

mroeder
mroeder

Reputation: 43

Ok, I found a solution my self. The problem was, that the opencv java wrapper was included with a system path. Now I use the maven install plugin within the validate live cycle step instead.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                    <configuration>
                        <groupId>org.opencv</groupId>
                        <artifactId>opencv</artifactId>
                        <version>3.3.0</version>
                        <packaging>jar</packaging>
                        <file>${project.basedir}/../lib/opencv/opencv-330.jar</file>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Works fine for me, but was not the way I wanted it to be... The system-path type dependency seems to be buggy in maven.

Upvotes: 2

Danylo Zatorsky
Danylo Zatorsky

Reputation: 6114

Try to add the following dependency to your ModuleA:

<dependency>
    <groupId>nu.pattern</groupId>
    <artifactId>opencv</artifactId>
    <version>2.4.9-7</version>
</dependency>

Upvotes: 0

Related Questions