On Fri, 22 Oct 2010, Imre András wrote:
Ok, thanks. After resolving this I got the following error:
jcc.cpp(294) : error C2039: 'fromJString' : is not a member of 'JCCEnv'
As I see this method is present in JCCEnv.h, but an #ifdef PYTHON
directive prevents to make it available for the tier code I intended to
write which would have been based on the jcc generated stub.
I am evaluating JNI wrappers. Our dev team need a layer that would ease
calling java code from native code. It also must have a clear and
documented interface, and should work with a trivial minimal example (Only
one class, contains a static and a normal method.)
No offense, but my opinion is that jcc is nice stuff, and surely makes
available Lucene for Python developers, but in its current state it seems
to be not suited for such a general-purpose JNI wrapper. Integration
should be staright, easy and straightforward, no matter what IDE or
compiler used.
I would suggest to go for setting up a minimal non-Python example that
demonstrates an example C++ code which calls java - in a clear and
separate environment (simulating the end user's). This will surely bring
up the issues - some of them I have tackled, but unfortunately I ran out
of time...
No offense taken. If you have the itch to make this work, then I'd be glad
to help you along the way. What you're trying to do, use jcc for C++ only,
was an intended use from the beginning. I think you're the first on this
list to actually try it. The Python support is built on top of the C++
support so I expect the C++ layer to be sound. From a compile/link
perspective, Python makes it easier as it knows how to invoke the
compiler/linker to produce a Python extension shared library (via
distutils). When using just C++, it's up to you to add to your project (via
the IDE, Makefile, whatever you chose), the files it generates and the
runtime files it needs to then run. There may be a few glitches such as the
ones you found but I'd expect this use to work without too much extra work.
The reason for JCC runtime for C++'s is pretty much only for tracking the
Java objects as they escape the JVM. It manages the global references that
get created when objects escape the JVM (this is something you have to do
manually if you used the JNI directly instead).
Using JCC in your project is a two-step process. First get JCC to generate
the C++ wraper code for the Java code you want access to. This is,
hopefully, well documented on the JCC site [1]. Then take that generated
code tree and the necessary JCC runtime source files [2] and add them to
your project's build. Any file that includes <Python.h> unconditionally is
not part of the code you should include.
The last problem you found has to do with the fact that the env global
variable is declared in a file only needed by the Python runtime; jcc.cpp
should not be included in your project and you need to declare that global
in code of yours instead.
Once you have a build, to then use it, you still need to write code to
startup and initialize the JVM (as documented in the Java Native Interface
docs [3]) and, before you call into any Java class, initialize it first via
that class' initializeClass() method.
Cheers !
Andi..
[1] http://lucene.apache.org/pylucene/jcc/documentation/readme.html
[2] JObject.cpp, JCCEnv.cpp, JCCEnv.h
[3] http://java.sun.com/docs/books/jni/html/invoke.html