2

I've found several instructions on how to import user-built .class and .jar files to JPype, but I seem to be having a lot of trouble getting anything working at all.

What works: I can import standard java stuff and print HELLO WORLD and such.

Some of what I've tried:

I've tried adding -Djava.class.path with the path to a jar containing the relevant class files, to a directory structure containing (several folders down) the relevant .class files, as well as '-Djava.ext.dirs'. I've recompiled and re-installed with a different JVM location. The class I am attempting to instantiate is Outer, public, and has a public constructor.

I'm using Python 2.6.1 on OSX 10.6.

My current test file: from jpype import *

startJVM(getDefaultJVMPath(), '-Djava.class.path=/Users/gestalt/Documents/msmexplorer_git/msmexplorer/MSMExplorer/build/classes')
java.lang.System.out.println("hello world")
msmexplorer = JPackage('org.joofee.meh.msmexplorer')
T = msmexplorer.MSMExplorer()
shutdownJVM()

If I use JClass I always get ClassNotFound exceptions from JPype; if I use JPackage I get Package not callable errors. Basically, JPype can't find my stuff.

Thanks so much!

EDIT (possibly helpful debugging stuff...): Is there a straightforward way to print which third party java classes are available/imported?

bcr
  • 1,328
  • 11
  • 27
  • Can you please share a working sample of executing class' function of a jar from Python using Jpype. I was not able to find a working sample, tried a couple of with options but fail with error 'not callable' – Sankalp Jan 22 '17 at 19:34

1 Answers1

0

Package not callable errors are referenced in this link) it would seem you need to make sure the java class file is accessible from the working directory. I am not sure how the jvm classpath comes into play, I would have thought how you did it would work.

You could also try loading the org package and then getting to the other packages through that one as the link I shared shows:

msmexplorer = JPackage('org').joofee.meh.msmexplorer T = msmexplorer.MSMExplorer()

  • thanks for the answer. A bit has happened since: I discovered that I didn't have as many problems instantiating other classes. The class declaration for the one I am having trouble with is: `public class MSMExplorer extends JPanel implements MSMConstants {`...so maybe the issue is that JPanel isn't imported? Also, I've heard that awt / swing support from JPype is minimal at best; unfortunately, my application is all swing, so I've been looking at other options (unless this is actually doable for jpype) – bcr Aug 02 '12 at 17:51