From: Antonio R. <An...@ho...> - 2001-09-17 02:47:24
|
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 |
From: Phil S. <psu...@es...> - 2001-09-17 13:26:19
|
I've been wrestling with the same problem, just posted to jython-dev about it in fact. As far as I can tell, what you want to do is not supported but you can add support with the following patch to org/jython/core/imp.java in jython-2.1a3: imp.java 498a499,502 > //if it's not a builtin or in the python path, try the classpath > ret = loadFromClassLoader(name, imp.class.getClassLoader()); > if (ret != null) return ret; > Then you need to add the standard modules to the jython.jar file. I have an ant file that does this if you're interested. -----Original Message----- From: Antonio Rodriguez [mailto:An...@ho...] Sent: Sunday, September 16, 2001 10:40 PM To: jyt...@li...; ds...@ri... Subject: Re: [Jython-users] import from jar--clarification 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 |
From: Phil S. <psu...@es...> - 2001-09-17 13:51:30
|
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 |
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 |
From: Samuele P. <pe...@in...> - 2001-09-17 22:59:01
|
Hi. > 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. Do you mean *$py.class files produced by the interp? you should be able to put them inside the jar and that should work, otherwise is a bug :) If you mean precompiled by jythonc ... that's another thing. > 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. > See above. In any case importing is implemented in org.python.core.imp and the various *PackageManager classes ... regards, Samuele Pedroni. |
From: Phil S. <psu...@es...> - 2001-09-18 14:49:46
|
<AntonioSaid> 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. </AntonioSaid> I believe I answered this directly in my first reply to your question. Apply this patch: org/jython/core/imp.java in jython-2.1a3: imp.java 498a499,502 > //if it's not a builtin or in the python path, try the classpath > ret = loadFromClassLoader(name, imp.class.getClassLoader()); > if (ret != null) return ret; > Note that I don't know the source code, just poked around for a couple of hours and this seems to work. |
From: Samuele P. <pe...@in...> - 2001-09-18 15:47:39
|
[Phil Surette] > <AntonioSaid> > 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. > </AntonioSaid> > > I believe I answered this directly in my first reply to your question. Apply > this patch: The patch does not load .class files. > > org/jython/core/imp.java in jython-2.1a3: > imp.java > 498a499,502 > > //if it's not a builtin or in the python path, try the classpath > > ret = loadFromClassLoader(name, imp.class.getClassLoader()); > > if (ret != null) return ret; > > This patch has been posted on jython-dev, nobody for the moment could comment and dedicate time on this regards, Samuele Pedroni PS: be patient ;) |
From: Carlos Q. <car...@we...> - 2001-09-17 07:58:02
|
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 |
From: dman <ds...@ri...> - 2001-09-18 02:27:36
|
On Sun, Sep 16, 2001 at 10:40:10PM -0400, Antonio Rodriguez wrote: | 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. Oh, now I see. You can use jythonc to compile a python program and all its dependencies into a single jar file (which is suitable for distribution as a java applet). Note, however, that the result from jythonc isn't .py files in a jar file but rather .class files in a jar file. HTH, -D |