OpenCV本机库未加载Maven

时间:2016-11-14 11:05:09

标签: java maven opencv

我正在尝试运行一个使用OpenCV库来渲染视频的基本程序。我得到的一个主要问题是maven在尝试加载依赖项(它使用的本机库)时报告错误。我在这里查看的所有解决方案,在GitHub和其他任何地方都没有结果。

这是pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <repositories>
    <repository>
      <id>javaopencvbook</id>
      <url>https://raw.github.com/JavaOpenCVBook/code/maven2/</url>
    </repository>
    </repositories>

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>mavenproject1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.javaopencvbook</groupId>
            <artifactId>opencvjar</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.javaopencvbook</groupId>
            <artifactId>opencvjar-runtime</artifactId>
            <version>3.0.0</version>
            <classifier>natives-windows-x86_64</classifier>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>


  <build>
  <plugins>
    <plugin>
      <artifactId>maven-jar-plugin</artifactId>
      <version>2.4</version>
      <configuration>
        <archive>
          <manifest>
            <addClasspath>true</addClasspath>
            <classpathPrefix>lib/</classpathPrefix>
            <mainClass>com.mycompany.mavenproject1.App</mainClass>
          </manifest>
        </archive>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.1</version>
      <executions>
        <execution>
          <id>copy-dependencies</id>
          <phase>package</phase>
          <goals>
            <goal>copy-dependencies</goal>
          </goals>
          <configuration>
            <outputDirectory>${project.build.directory}/lib</outputDirectory>
            <overWriteReleases>false</overWriteReleases>
            <overWriteSnapshots>false</overWriteSnapshots>
            <overWriteIfNewer>true</overWriteIfNewer>
          </configuration>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <groupId>com.googlecode.mavennatives</groupId>
      <artifactId>maven-nativedependencies-plugin</artifactId>
      <version>0.0.7</version>
      <executions>
        <execution>
          <id>unpacknatives</id>
          <phase>generate-resources</phase>
          <goals>
            <goal>copy</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

</project>

这应该创建opencvjar-3.0.0.jar和opencvjar-runtime-3.0.0-natives-windows-x86_64.jar

还应设置此所需的系统路径。在%PATH%变量中,我添加了原生.jar的路径。就我而言,项目位于

  

D:\ AleksandarRakic \ Java Projects \ mavenproject1

当本地库位于

  

D:\ AleksandarRakic \ Java Projects \ mavenproject1 \ target \ natives

我正在使用 NetBeans 8.2 。当我清洁&amp;构建项目它显示以下错误/警告:

The POM for org.javaopencvbook:opencvjar-runtime:jar:natives-windows-x86_64:3.0.0 is missing, no dependency information available

无论我使用何种版本的OpenCV,上述错误都会持续存在。我也尝试过放置3.1.0版本,但之后它也说缺少核心jar。

我失去了两天试图解决这个问题,欢迎任何帮助。

1 个答案:

答案 0 :(得分:0)

问题在于maven和OpenCV版本。

如果我将OpenCV版本设置为3.0.0并且如果我将3.1.0版本加载到核心.jar,那么Maven将不会加载本机.dll

我做了一件显而易见的事情,做了一个没有maven的空白项目,添加了正确的库并且运行得很好