views:

1356

answers:

1

I am trying to use maven to build a project that depends on a JNI wrapper around the OpenCV computer vision library. I've been able to "maven-ize" the OpenCV wrapper here: http://ubaa.net/shared/processing/opencv/ by using FreeHEP's NAR maven plugin, but the documentation for that plugin is somewhat lacking.

I've been able to create a project (imagedetect) that depends on the OpenCV jni project (I'm calling that OpenCVJava). imagedetect will compile, however, any test, integration-test, or package target fails with an error about libraries missing from the java.library.path.

!!! required library not found : no OpenCV in java.library.path
Verify that the java.library.path property is correctly set and 'libcxcore.so', 'libcv.so', 'libcvaux.so', 'libml.so', and 'libhighgui.so' are placed (or linked) in one of your system shared libraries folder

This is particularly frustrating -- the only way I know to resolve this is to somehow track down the .nar file for the opencv libraries, manually extract them, set the java.library.path, and then invoke the gnaraly java command to actually execute the tests/application with the proper classpath / library path. This isn't going to work--particularly if this problem persists to transitive dependencies.

How can I make this build/test/execute system cleaner? I'm not set on FreeHEP, but I would like to stick with maven, since it makes our most common use-cases much simpler.

FreeHEP Nar plugin: http://java.freehep.org/freehep-nar-plugin/intro.html

+2  A: 

I'm not familiar with FreeHEP, but if you're having trouble setting the java.library.path on surefire to run your tests, I found an example at: http://buildanddeploy.com/node/14 It's a bit involved to post , but shows how to get maven to copy the native libs to a directory which you then point your java.library.path at. I've used a similar approach myself in the past.

Also looking at the error, did you need to set LD_ LIBRARY_ PATH to fix it? If so you should get this set within maven as well.

Here's an example of how to set this for surefire (from http://docs.codehaus.org/display/MAVENUSER/Projects+With+JNI): maven-surefire-plugin once target/tmplib java.library.tmpdir target/tmplib

bm212
Thanks! (I know, this is very, very late) The codehaus link works great.
rcreswick
To clarify for anyone reading this: the CodeHaus link describes a method that *does not* require setting LD_LIBRARY_PATH, or any other environment variables. The resulting jar contains all the compiled libraries, and calling code doesn't need to know anything about JNI.
rcreswick