LeeKamentsky / python-javabridge

Python wrapper for the Java Native Interface
Other
116 stars 62 forks source link

Documentation for High-level API is sparse #80

Open rhoerbe opened 8 years ago

rhoerbe commented 8 years ago

There is a gap between hello world and the more involced code in Weka or othe projects. Where can I find an example how to actually create objects and call methods? My task has fairly APIs, e.g. calling a self-written wrapper class to Xerces to do XML schema validation.

LeeKamentsky commented 8 years ago

The two most useful classes, JWrapper and JClassWrapper are not highlighted that well in the docs. Basically, you use JClassWrapper to get an object representing a class and use it to instantiate objects, call static functions and access static variables:

# Get the java.class.path property using the static call, System.getProperty
javabridge.JClassWrapper("java.lang.System").getProperty("java.class.path")
# Get an instance of a java.io.File and then check if it can be executed
my_file = javabridge.JClassWrapper("java.io.File")("/usr/bin/java")
assert my_file.canExecute()

If a static call or constructor returns a Java object, Javabridge wraps that in a javabridge.JWrapper. If you use the low-level functions, you can do that too.

But you are right, docs are sketchy, so I'll leave this as open.

deepzf commented 7 years ago

@LeeKamentsky i also need an detailed document too,how to actually create objects and call methods use my own jar package