Problem accessing JVM class

220 views
Skip to first unread message

Henry Pinkard

unread,
Sep 25, 2018, 1:15:42 PM9/25/18
to Py4J Support and Comments
Hi, I'm trying to run some code from python accessing a JAR file with some a Java class that I wrote. I start the Java gateway like this:

classpath = '/path/to/jar/file.jar'
self.javagateway = JavaGateway.launch_gateway(classpath=cp, javaopts=['-Xmx4096m'], die_on_exit=True)

This works, and I can access standard Java classes within the JVM. However, I am unable to access the class within the jar.I get the following error:

TypeError: 'JavaPackage' object is not callable

As far as I can tell this means either py4j can't find the constructor I'm calling, or the JVM can't find it. Strangely, I can query the JVM for its classpath and my jar shows up. I do this using:

self.javagateway.jvm.java.net.URLClassLoader.getSystemClassLoader().getURLs()[1].getFile()

I'm doing this on an Ubuntu system, and I've gotten the same exact code to work on a different Ubuntu system, with same version of Java, python, py4j. I've now tried it on an additional Ubuntu system and run into the same problem. Does anyone have any suggestions for how I might be able to fix or debug this?

Henry

Barthelemy Dagenais

unread,
Oct 13, 2018, 5:33:35 AM10/13/18
to py...@py4j.org
Hi,

thanks for using Py4J! From what I can see, you are correctly using the API. We would thus need a bit more information to help you.

Is the jar file readable from your user? The fact that you can see the file path in the system class loader is not enough: even if you provided a bad path, it would still show up.

Is the jar file compatible with the default JVM you are using?

Are you using the same Ubuntu version as before or is something different?

Can you provide a short code example that demonstrates where the TypeError occurs?

Thanks,
Bart



--
You received this message because you are subscribed to the Google Groups "Py4J Support and Comments" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4j+uns...@py4j.org.
To post to this group, send email to py...@py4j.org.
To view this discussion on the web visit https://groups.google.com/a/py4j.org/d/msgid/py4j/c54a900f-a65b-4061-b6d5-2cf0fea094a3%40py4j.org.
Reply all
Reply to author
Forward
0 new messages