Create java executable which can run without opencv.

999 views
Skip to first unread message

Robik

unread,
May 3, 2012, 11:52:10 AM5/3/12
to javacv
I installed OpenCV on my computer and then I used JavaCV to create an
application.

Is there a way to create an executable jar which would run on any
computer even if it does not have OpenCV installed in it? Plus, the
distributable application should only contain the files (of OpenCV)
which it actually uses i.e. not the entire OpenCV.

It is okay if I need to create separate executable files for Linux and
Windows.

It would be best if someone could provide a tutorial.

Finally, I have heard of JNI but never actually used it. So, please do
not just say "use JNI" or something like that. A simple tutorial would
be really helpful!!

Samuel Audet

unread,
May 3, 2012, 8:06:56 PM5/3/12
to jav...@googlegroups.com
Sure, we can trim JavaCV and rebuild everything with JavaCPP in any way
we want!

Start by reading the README.txt file of JavaCPP and let me know how that
sounds.

Samuel

Robik

unread,
May 3, 2012, 8:47:17 PM5/3/12
to javacv
Thank you.. I will read it. I will post more questions if I have any.
Message has been deleted

Robik

unread,
May 3, 2012, 9:07:13 PM5/3/12
to javacv
Two Questions:

1. Does this mean that we need to write java code for every C++ file,
the java app is dependent on? We do not want that. We just want to use
JavaCV and have an AUTOMATIC mechanism to generate jar file which does
not require any OpenCV installation (best of both worlds!).

2. How would I build a single jar file that is runnable on any
computer with java? i.e. somehow include the C++ libraries within the
jar file (not requiring separate .dll or .so files).


Samuel Audet

unread,
May 3, 2012, 9:34:45 PM5/3/12
to jav...@googlegroups.com
We can link with the static libraries of OpenCV, that should do what you
want. And then we can create a single JAR of the result. No need to
write any Java code..

Setting the "compiler.linkpath" property to the path of the static
library on Windows, and adding "-static" to the "compiler.output.prefix"
property on Linux should do the trick, but I haven't tested it, so let
me know if you encounter any problems.

It's probably a good idea to produce only one library file in that case
using the "-o" option of JavaCPP, otherwise we are going to get
opencv_core inside each library file..

Robik

unread,
May 3, 2012, 11:13:12 PM5/3/12
to javacv
Thanks. I will try it with Netbeans and I will post more replies if I
find any problem.

Samuel Audet

unread,
May 12, 2012, 10:47:50 AM5/12/12
to jav...@googlegroups.com
I've just released a new version of JavaCV that makes it easier to
create static libraries. Basically
1. Delete any source files you do not need.
2. Build with JavaCPP options like "-Xcompiler -Wl,-static -o javacv",
e.g.: mvn install -Djavacpp.options="-Xcompiler -Wl,-static -o javacv"
or whatever is appropriate for other platforms.
3. In your code, call Loader.load(opencv_core.class, "javacv") to
initialize.

Samuel

Samuel Audet

unread,
Nov 30, 2012, 11:22:08 PM11/30/12
to jav...@googlegroups.com
Hello,

What's missing from the precompiled libraries? If you don't need to
recompile anything, then don't try to!

On 11/28/2012 10:04 AM, monsif mabrouk wrote:
> Hi samuel ,
> i'm experiencing the same problem but i do not have any experience in
> compiling files i usualy use eclipse...so could you please tell me how
> did you do to get it to work,
> -how to compile opencv libs to static
> -how to link it .... im reaaaly stuck
> thaks alot.

Reply all
Reply to author
Forward
0 new messages