I ended up using a java version of the same package and calling that
Its not the most ideal setup however now I don't need to figure out
how to get jython to pick up the python module.
On Thu, Sep 24, 2009 at 9:32 PM, Ryan Crumley <crumley@...> wrote:
> Unfortunately switching the direction from python->java is not an
> option. Although even then I wonder how jython would resolve an import
> statement from the __run__.py that is contained in the jar. What makes
> that situation different than what I am trying to do now? Seems like I
> am missing an important part of how jython molds python code into the
> java classpath.
> On Thu, Sep 24, 2009 at 1:39 PM, David Handy <David.Handy@...> wrote:
>>> -----Original Message-----
>>> From: Ryan Crumley [mailto:crumley@...]
>>> Sent: Thursday, September 24, 2009 1:38 PM
>>> I have a piece of java code that uses a concept similar to
>>> JythonFactory to load a python file, instantiate a python class and
>>> return it to java so I can call methods on its interface. This is
>>> working perfectly. Now I would like to enhance my python class by
>>> using a python module provided by a 3rd party so I put this module in
>>> the root of my classpath (lets call it 'chardet',
>>> http://chardet.feedparser.org/) and add 'import chardet' to the top of
>>> my python file.
>>> As you may have guessed jython can not locate the module:
>>> The reason I am loading the python file from an iostream and why I
>>> would like the python module to live in the classpath is because I
>>> need to ship this java program as a single self contained jar. Can
>>> anyone give me advice on how best to set this up?
>> So you want to ship a Java program as a self-contained jar, and you have both Java and Jython code. It also sounds like you have control over what goes in this program.
>> If it were me, I'd seriously consider using the stand-alone jython jar and add your java classes to it. Put your main entry code in a __run__.py file in the root of the jar file. Then, instead of using a JythonFactory and calling Jython from Java, go the other direction and have your main python code instantiate Java classes as needed and call methods on them. If you have that much control over this program.
>> http://wiki.python.org/jython/InstallingJython#Standalonemode - how to get a stand-alone jython jar
>> http://wiki.python.org/jython/UserGuide#invoking-the-jython-interpreter - how to start __run__.py file in a jar
>> But, you probably want to make your current approach work, and that I can't help with much. Maybe someone else on the list can.
>> David H