From: Brandon P. <bp...@gm...> - 2010-09-30 19:40:32
|
So I was trying different things and I realized that actually doing sys.path.append(jar_file) doesnt work in this case at all. I actually was messing around with different things and did Py.getSystemState().packageManager.addJar(jar_file, True) and it cached the package (which made it appear that sys.path.append was working)... But I guess addJar() doesn't actually help which causes the symptoms below, so the question still stands, if adding to sys.path does not work, how else can I import a jar file dynamically? -Brandon On Thu, Sep 30, 2010 at 1:21 PM, Brandon Pedersen <bp...@gm...> wrote: > Hi all, > > We are running a somewhat customized version of Jython and I am trying > to dynamically load a jar from the file system and import a class. I > do: > > sys.path.append(jar_file) > import com.vmware.vim25.mo.ServiceInstance > > This throws an ImportError saying it cannot import the name > ServiceInstance. However, if I do: > > sys.path.append(jar_file) > import com.vmware.vim25.mo > print dir(com.vmware.vim25.mo) > > It will list ServiceInstance as available....I am thoroughly confused > as to how this is possible. > > I am sure it has to do with how we are running jython since this works > using a regular jython script, but I am not sure what to look for. Is > there some property we arent setting when we initialize the jython > interpreter instance? is there some other way to add the jar or notify > the package manager of the new jar and process it like it does on > startup? > > I realize this may be a long shot without knowing exactly how we are > using jython but thanks for any help, > > -Brandon > |