Search code examples
javapython-2.7jpype

Jpype passing arguments to Java


I have a java programmer with following line

service.loadPropertiesForItems(Inbox, new PropertySet(ItemSchema.Subject, ItemSchema.Body));

Program calls classes and methods from external jars.

I want to write equivalent code in python which calls external jars like my java program does. Using Jpype I implemented the code but it fails on following line

service.loadPropertiesForItems(inbox, ewsPkg.PropertySet(ewsPkg.ItemSchema.Subject,   ewsPkg.ItemSchema.Body))

Here PropertySet, ItemSchema are classes which I use from external jar. ItemSchema.Subject and ewsPkg.ItemSchema.Body are class type

Running the code I get following error on line mentioned above -

service.loadPropertiesForItems(inbox, ewsPkg.PropertySet(ewsPkg.ItemSchema.Subject, ewsPkg.ItemSchema.Body))
File "C:\Python27\lib\site-packages\jpype\_jclass.py", line 79, in _javaInit
  self.__javaobject__ = self.__class__.__javaclass__.newClassInstance(*args)
RuntimeError: No matching overloads found. at src/native/common/jp_method.cpp:121

Thanks


Solution

  • As suggested by Martin https://github.com/originell/jpype/issues/117

    following code works well

    ItemSchema = ewsPkg.ItemSchema
    PropertyDefinition = ewsPkg.PropertyDefinition
    Subject = ItemSchema.Subject
    Body = ItemSchema.Body
    
    args = JArray(PropertyDefinition)([ItemSchema.Subject, Body])
    PropertySet = ewsPkg.PropertySet(args)