2014-03-26 420 views
5

我需要構建包含OpenCV的項目。這會很好,但由於某些原因,庫不會進入庫java.library.path。當我嘗試使用庫運行的代碼我得到這個錯誤:使用Maven使用OpenCV構建Java項目

* 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 /共享/行家 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-通用」,拱: 「I386」 家庭: 「UNIX」

UNAME -a

Linux的PC-1 3.11.0-14泛型#21,Ubuntu的SMP星期二十一月12 17:07:40 UTC 2013 i686 i686 i686 GNU/Linux

+0

你運行什麼命令? IMO java.library.path選項不會自動設置。它應該指向一個包含OpenCV本地模塊的目錄。 – Tome

+0

@Tome,mvn包。所有* .so文件被認爲是在目錄/ com/googlecode/javacv/cpp/linux-x86_64 /和/ com/googlecode/javacv/cpp/linux-x86/ – ftp27

+0

的結果* .jar文件中據我所知,so文件在打包到JAR文件時沒有被使用,它們必須可以直接從文件系統訪問,所以通常最終會得到類似於/ lib /的結構,用於您的jar和/ bin /(或其他) so/dll文件。/bin /必須是運行程序時必須提供的java.library.path VM選項的值。 – Tome

回答