issues with interfacing SikuliX jar with C++ using JNI

Asked by Priyesh

I am working on a c++ project, i wanted to use sikuli. The jar is loaded properly. Then the problem i am facing is when i try loading the "Runtime class" through the JNI (FindClass) interface it is returning NULL.

So we are not able to pinpoint the issue with this. So we need the following information:
1) Has anybpody previously tried using sikulixapi.jar with C++ using JNI ? and do we have any working example of that ?
2) Are there any build instruction to build the sikulixapi.jar with the Debug info ?

Please do the needful and help me out.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Wooouuw, that is overkill ;-)

The Sikuli project once was born to wrap the OpenCV features in Java using C++ and JNI, to be able to use the same high level API and Java based scripting languages on Windows, Mac and Linux.

When you are in C++ anyway, then you should use the C++ API of OpenCV directly. That all is rather simple and OpenCV has all needed features to handle image files.

About screenshots and keyboard/mouse handling, I do not know the libraries needed, but her again it would be much easier to directly access the Java Robot class.

The class RunTime is the new bootstrap/startup class and it is at org.sikuli.script.
It is a singleton, has no public constructor and is initialised using RunTime.get()

Revision history for this message
Priyesh (impriyesh) said :
#2

Raiman,

Then what do you recommend for me ? is there any other way apart from JNI which can make it possible for me to use sikuli in a c++ project ?

Revision history for this message
Best RaiMan (raimund-hocke) said :
#3

It depends on what you want to achieve:

-- use single API features in your C++ code
... by directly calling these methods (your JNI approach).

as mentioned: overkill in my opinion
... and needs very good reasons to do that (I cannot see any though)

-- run short workflow snippets
... at specific points in your C++ code
For this I would suggest to use JavaScript scripts and run them in a subprocess using
java -jar sikulixapi.jar -r somescript.sikuli

where somescript.sikuli is a folder containing the needed images and a somescript.js containing the workflow

Using JNI, you might use
org.sikuli.script.Runner.run("path-to-somescript.sikuli", args-array)

the advantage: the startup delay is rather short compared to the Jython scripts running.

If interested in this solution: come back and tell me more about your usage scenario

-- with 1.1.0 final (available in one of the next nightlies)
... there will be a RunServer (specially started sikulixapi.jar) that waits for socket-based requests, which can be single API calls and/or complete script snippets to be run. The server can be on the same machine or somewhere in the TCP/IP network.
This is mainly implemented, to support any environments, that cannot integrate with Java directly (like C++, C# and others)

Revision history for this message
Priyesh (impriyesh) said :
#4

Thanks for the perfect reply, Saved a lot of time. Javascript running is sub process worked perfectly for my requirement.

Revision history for this message
Priyesh (impriyesh) said :
#5

Thanks RaiMan, that solved my question.