From: Antonio R. <An...@ho...> - 2001-09-17 22:05:23
|
Thanks to all who answered my original question. I wanted to put a caveat in the archive for future reference. This scheme works well but appears a bit finicky. Namely, if you pre-compile the standard python library into .class files (to save time later), they will not load from a jar. Also, the jar should have the structure Lib/***.py as opposed to just **.py at the top level or it won't work. One question to those of you who know the source. In what class does the bulk of the loading take place? I want to be able to load both *.class files and *py files and I don't think it should be too bad of a change. Does anyone have a reason as to why this would be a _bad_ idea. I figure it can only make things faster... Antonio -|Phil Surette <psu...@es...> wrote on Mon Sep 17 09:46:35 EDT 2001: Great tip Carlos! So, if you change to your jython home directory and create a lib.jar like this: >jar -cvf lib.jar Lib Then you can invoke jython like this: >java -cp jython.jar -Dpython.path=lib.jar!Lib org.python.util.jython and all your imports will work... To verify that the .py files are really coming from lib.jar and not from the $JYTHON_HOME/Lib directory, you might want to rename the Lib directory temporarily. Jython seems to be able to search for the Lib directory based on the location of jython.jar, though how it does this I do not know. -----Original Message----- From: Carlos Quiroz [mailto:car...@we...] Sent: Monday, September 17, 2001 3:55 AM To: jyt...@li... Subject: Re: [Jython-users] import from jar--clarification On Monday 17 September 2001 05:40, Antonio Rodriguez wrote: To do this you can bundle your py file into a subdir for the module, let say subdir util and filt util1, then it will be in the jar util.jar. You can add the jar to the sys.path by doing import sys sys.path.append("/path/to/jar/util.jar!util"); after this is possible to do from util import util1 You can also do this in java via PySystemState sys = Py.getSystemState(); sys.path.append(new PyString("/path/to/jar/util.jar!util")); Notice that this works only in jython 2.1a3 Therefore you can bundle all standard libraries in a lib.jar and do sys.path.append("/path/to/jar/lib.jar!Lib") Regards > Let me clarify: > > Im not asking how to put classes in the classpath. I'm asking how to put > all of the standard python library (the .py modules like re.py and > httplib.py) that compile to *$py.class into a jar in such a way that when a > PythonInterpreter runs over the line: import re, it can import the python > library from a jar. > > > Thanks. > > > -|dman <ds...@ri...> wrote on Sun Sep 16 20:56:03 EDT 2001: > > On Sun, Sep 16, 2001 at 05:11:10PM -0400, Antonio Rodriguez wrote: > | How do I put a jar in the path of a PythonInterpreter object? > > $ java -help > Usage: java [-options] class [args...] > (to execute a class) > or java -jar [-options] jarfile [args...] > (to execute a jar file) > > where options include: > -client to select the "client" VM > -server to select the "server" VM > -classic to select the "classic" VM > If present, the option to select the VM must be first. > The default VM is -client. > > -cp -classpath <directories and zip/jar files separated by :> > set search path for application classes and resources > -D<name>=<value> > set a system property > -verbose[:class|gc|jni] > enable verbose output > -version print product version and exit > -showversion print product version and continue > -? -help print this help message > -X print help on non-standard options > > $ > > > The use -classpath option to the JVM you run jython with. > > HTH, > -D > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users _______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users _______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users |