|
From: <bc...@wo...> - 2001-03-07 14:07:00
|
[Kiran R Karkera]
>hi.. can you point out to me some examples of setting the namespace using
>the PythonInterpreter(Pydict ) constructor ?
Do you mean binding a name in the PythonInterpreter namespace to a
value? You can use the PythonInterpreter.set() methods for that.
>I cant seem to find any.
>Also, can you point out the mechanism by which jython, (when embedded and
>called from a java app) finds and loads its java classes ?
Not in just a few words <wink>.
Generally java classes are loaded with the classloader that loaded
jython (except for java classes found on sys.path, but I will ignore
that for now).
Assuming that your classpath is setup correctly, that means that code
like:
import java
java.lang.Class.forName("name.of.my.javaclass")
will work in 9 out of 10 cases. If it doesn't return the expected java
class, it is a problem with your classpath setup or your classloaders.
An entirely different issue is the detection of java *packages*. Jython
inspect all the directories and .jar files it can find in order to
decide whether a name (say "javax") is in fact a java package. If some
classes gets loaded by a custom classloader, Jython will be unable to
find the actual classes and thus are unable to find all the package
names used by the java classes. As a result, the import statement can
not find the java packages and java classes.
The org.python.util.PyServlet contains two examples on how you can
convince jython into inspecting other locations for java packages
(WEB-INF/lib and WEB-INF/classes).
>I want some
>java classes to be loaded by default when jython starts up, rather than
>doing "import foo from bar" in the .py scripts. Is there an API to do this
PythonInterpreter interp = new PythonInterpreter();
interp.set("foo", Class.forName("bar.foo"));
regards,
finn
|