You can set sys.classLoader.
There's a verbosity flag you set so that Jython prints
copious information about where it is looking for imports.
I don't understand the conclusion that the classloader
is related to py module import failures.
Brian Merrell wrote:
> I reported a problem last year regarding the inability to import the
> standard library when using Jython with a large commercial
> application. I recently followed-up with the vendor and received a
> response that may shed some light on the issue. However I am afraid I
> am too inexperienced with Jython/Java to completely understand its
> implications. The vendor isn't particularly interested in supporting
> Jython so I am kind of stuck in the middle trying to see if there is
> anything we can do. Here is the vendor's explanation of the issue.
>
> """XXXXX uses a separate classloader for plugins for several reasons.
> (Security, interoperability, etc.) The Jython implementation here
> doesn't appear to have a way to set or configure the classloader - it
> only uses the default classloader. If you can figure out how to tell
> Jython which classloader to use to look up resources, then it should
> work. Just have the plugin pass Jython the plugin's classloader.
> Sometimes, classloader issues can be gotten around by setting the
> classloader of the current thread before (and then putting the old one
> back after) a call. However, from the bug complaints online, that
> trick doesn't work with Jython.
>
> So, what you're looking for is "Jython needs to use an arbitrary,
> settable classloader." If you want to test it/repro it, create a
> custom classloader that knows all about Jython, and have the regular
> system not know Jython. Have some code inside the custom classloader
> make the Jython calls you are trying to make here. If you don't get
> the same errors, send me your testbed and I'll take another look."""
>
>
> I am afraid classloaders (and particularly custom ones) are news to
> me. Anyone have any insights?
>
> -brian
>
> On Wed, Dec 9, 2009 at 4:22 PM, Brian Merrell <brian@...
> <mailto:brian@...>> wrote:
>
> I've compiled the jar as standalone and am still having the same
> problem. "import sys" work but "import os" mysteriously fails (as
> does most other standard library imports). Do I need to modify
> sys.path in some way? How do I tell which standard-library
> modules the interpreter can see?
>
> -brian
>
>
> On Tue, Dec 1, 2009 at 5:08 AM, Alan Kennedy <jython-dev@...
> <mailto:jython-dev@...>> wrote:
>
> [Brian]
> > I've add the contents of jython.jar into the application's
> jar and am able
> > to invoke a PythonIntepreter on scripts also contained
> within the jar. I
> > run into problems however when I try to use the
> Jython/Python standard
> > library. import sys works but import os fails, presumably
> because
> > jython.jar does not contain the standard library? I've
> tried adding the
> > standard library (the Lib directory under c:\jython) but I
> can't seem to
> > figure out where to put it in the application jar so that the
> > PythonInterpreter can see it. I've tried simply creating a
> directory \MyLib
> > and adding it to the sys.path but this doesn't seem to
> work. Any ideas?
>
> Have you tried using the standalone version of jython?
>
> If you select the "standalone" installation of jython, then the
> resulting jar installed on your system contains the Lib/ directory
> within the jar.
>
> http://wiki.python.org/jython/InstallingJython
>
> HTH,
>
> Alan.
>
> ------------------------------------------------------------------------------
> Join us December 9, 2009 for the Red Hat Virtual Experience,
> a free event focused on virtualization and cloud computing.
> Attend in-depth sessions from your desk. Your couch. Anywhere.
> http://p.sf.net/sfu/redhat-sfdev2dev
> _______________________________________________
> Jython-users mailing list
> Jython-users@...
> <mailto:Jython-users@...>
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Protect Your Site and Customers from Malware Attacks
> Learn about various malware tactics and how to avoid them. Understand
> malware threats, the impact they can have on your business, and how you
> can protect your company and customers by using code signing.
> http://p.sf.net/sfu/oracle-sfdevnl
> ------------------------------------------------------------------------
>
> _______________________________________________
> Jython-users mailing list
> Jython-users@...
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
|