Home OpenCV with Java Gradle Project as fat jar
Reply: 0

OpenCV with Java Gradle Project as fat jar

user2785
1#
user2785 Published in July 17, 2018, 7:53 am

I am actually Trying to use OpenCV in Java based Gradle Project. Since, OpenCV needs native library and Jar File for execution. I am trying to wrap native library and Jar together using gradle, but I am facing errors in doing so.

When I try to run project, project is not able to find native library for opencv jar and giving me below error

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java340 in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at Library.(Library.java:9)

Although, I know how to set native library manually in Gradle project but I am not sure how to do it via Gradle and wrap native library in fat jar. Here is my build.gradle

// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

configurations {
    // configuration that holds jars to include in the jar
    openCVLibs
}

dependencies {
    openCVLibs fileTree(dir: 'libs', include: '*.jar')
    openCVLibs fileTree(dir: 'libs', include: '*.so')
    configurations.compile.extendsFrom(configurations.openCVLibs)
}

jar {
    from {
            configurations.openCVLibs.collect { it.isDirectory() ? it : zipTree(it) }
    }
    manifest {
        attributes('Implementation-Title': project.name,
                   'Implementation-Version': project.version)
    }
}

have also included link of sample eclipse project

So Here is edit Based on @kerry's comment I tried to crate mvn artifact following openCV Maven, but now I am facing following error while creating mvn build

[ERROR] Failed to execute goal org.codehaus.mojo:properties-maven-plugin:1.0.0:read-project-properties (set-arch-properties) on project opencv: Properties could not be loaded from File: /media/nitish/8EE47633E4761E21/opencv-3.4.0/build/build.properties -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:properties-maven-plugin:1.0.0:read-project-properties (set-arch-properties) on project opencv: Properties could not be loaded from File: /media/nitish/8EE47633E4761E21/opencv-3.4.0/build/build.properties

There is no build.properties file present in build folder. Since build folder is created by maven task only, so build.properties file should be created by maven only.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.330633 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO