I am using the client server example that is being shared in the py4j site(i am new to this)
tried the below code to invoke gateway along with client server configuration:
from py4j.clientserver import ClientServer, JavaParameters, PythonParameters
from py4j.java_gateway import JavaGateway, GatewayParameters
class EclipseAction(object):
"""Simple implementation of an EclipseRunnable that opens
a MessageDialog in the current thread. It must thus be
called from a UI thread.
"""
def __init__(self, clientserver):
self.clientserver = clientserver
def run(self, viewer):
workspace_root = self.clientserver.jvm.org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot()
project_names = [project.getName() for project in workspace_root.getProjects()]
#print(project_names[0])
addressDictionary = self.clientserver.jvm.xxx.accessAddressDetails(project_names[0])
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_field=True))
for key, value in addressDictionary.items():
print(value.city)
print(value.toString())
#self.clientserver.jvm.org.eclipse.jface.dialogs.MessageDialog.openInformation(viewer.getControl().getShell(), "Sample View", "HELLO FROM PYTHON")
class Java:
implements = ["org.py4j.plugin_example.EclipseRunnable"]
action = EclipseAction(None)
clientServer = ClientServer(JavaParameters(), PythonParameters(), action)
# Small hack so that action can call Java
action.clientserver = clientServer
But the value.city didnt return the actual field value. it returns the <py4j.java_gateway.JavaMember object at 0x0000022DA8DF95F8>
Also, have a query,
With the example plugin, Shall i access the code in static method of a java code using python on the initial run without invoking the Sample View Action button? Could you please elaborate on steps.