使用Maven使用OpenCV构建Java项目

时间:2014-03-26 14:21:19

标签: java linux maven opencv native

我需要构建一个涉及OpenCV的项目。它会很棒,但由于某种原因,库不会进入java.library.path库。当我尝试使用库运行代码时,我收到此错误:

* java.lang.UnsatisfiedLinkError:java.library.path中没有jniopencv_highgui *

的pom.xml

<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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>ru.intemsys.reget.server</groupId>
  <artifactId>reget-server</artifactId>
  <version>0.1-alpha</version>
  <packaging>jar</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.build.timestamp.format>yyyyMMddhhmm</maven.build.timestamp.format>
    <platform.name>${os.name}-${os.arch}</platform.name>
    <product.year>2014</product.year>
    <jdkVersion>1.6</jdkVersion>
    <javacpp.version>0.7</javacpp.version>
    <javacv.version>0.7</javacv.version>
  </properties>

  <dependencies>
    <dependency>
        <groupId>commons-daemon</groupId>
        <artifactId>commons-daemon</artifactId>
        <version>1.0.10</version>
    </dependency>

      <dependency>
          <groupId>com.googlecode.javacpp</groupId>
          <artifactId>javacpp</artifactId>
          <version>${javacpp.version}</version>
      </dependency>
      <dependency>
          <groupId>com.googlecode.javacv</groupId>
          <artifactId>javacv</artifactId>
          <version>${javacv.version}</version>
      </dependency>
      <dependency>
          <groupId>com.googlecode.javacv</groupId>
          <artifactId>javacv</artifactId>
          <version>${javacv.version}</version>
          <classifier>linux-x86</classifier>
      </dependency>

      <dependency>
          <groupId>com.googlecode.javacv</groupId>
          <artifactId>javacv</artifactId>
          <version>${javacv.version}</version>
          <classifier>linux-x86_64</classifier>
      </dependency>

    <dependency>
        <groupId>com.xeiam.xchart</groupId>
        <artifactId>xchart</artifactId>
        <version>2.3.1</version>
    </dependency>

    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
  </dependencies>

  <repositories>
      <repository>
          <id>javacpp</id>
          <name>JavaCPP</name>
          <url>http://maven2.javacpp.googlecode.com/git/</url>
      </repository>
      <repository>
          <id>javacv</id>
          <name>JavaCV</name>
          <url>http://maven2.javacv.googlecode.com/git/</url>
      </repository>
  </repositories>

  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${jdkVersion}</source>
                    <target>${jdkVersion}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeScope>compile</includeScope>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <classpathLayoutType>simple</classpathLayoutType>
                            <mainClass>ru.intemsys.reget.server.App</mainClass>
                            <packageName>ru.intemsys.reget.server</packageName>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <finalName>${artifactId}-${version}</finalName>
                </configuration>
            </plugin>
        </plugins>
  </build>

    <profiles>
        <profile>
            <id>linux</id>
            <activation>
                <os><name>linux</name></os>
            </activation>
            <properties>
                <os.name>linux</os.name>
            </properties>
        </profile>
        <profile>
            <id>macosx</id>
            <activation>
                <os><name>mac os x</name></os>
            </activation>
            <properties>
                <os.name>macosx</os.name>
            </properties>
        </profile>
        <profile>
            <id>windows</id>
            <activation>
                <os><family>windows</family></os>
            </activation>
            <properties>
                <os.name>windows</os.name>
            </properties>
        </profile>
        <profile>
            <id>i386</id>
            <activation>
                <os><arch>i386</arch></os>
            </activation>
            <properties>
                <os.arch>x86</os.arch>
            </properties>
        </profile>
        <profile>
            <id>i486</id>
            <activation>
                <os><arch>i486</arch></os>
            </activation>
            <properties>
                <os.arch>x86</os.arch>
            </properties>
        </profile>
        <profile>
            <id>i586</id>
            <activation>
                <os><arch>i586</arch></os>
            </activation>
            <properties>
                <os.arch>x86</os.arch>
            </properties>
        </profile>
        <profile>
            <id>i686</id>
            <activation>
                <os><arch>i686</arch></os>
            </activation>
            <properties>
                <os.arch>x86</os.arch>
            </properties>
        </profile>
        <profile>
            <id>amd64</id>
            <activation>
                <os><arch>amd64</arch></os>
            </activation>
            <properties>
                <os.arch>x86_64</os.arch>
            </properties>
        </profile>
        <profile>
            <id>x86-64</id>
            <activation>
                <os><arch>x86-64</arch></os>
            </activation>
            <properties>
                <os.arch>x86_64</os.arch>
            </properties>
        </profile>
    </profiles>
</project>

mvn -version

Apache Maven 3.0.4 Maven主页:/ usr / share / maven Java版本:1.7.0_25,供应商:Oracle Corporation Java home:/ usr / lib / jvm / java-7-openjdk-i386 / jre 默认语言环境:ru_RU,平台编码:UTF-8 操作系统名称:“linux”,版本:“3.11.0-14-generic”,arch:“i386”,系列:“unix”

uname -a

Linux PC-1 3.11.0-14-generic#21-Ubuntu SMP Tue Nov 12月17日17:07:40 UTC 2013 i686 i686 i686 GNU / Linux

1 个答案:

答案 0 :(得分:2)

有一个solution。所有的库都在javacv-0.6-cppjars.zip