Stuck on standard imports

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Stuck on standard imports

Michael Litherland
Hi,

I've searched the documentation and the list archives as well as I could and though I've seen somewhat similar queries I haven't found any solutions yet.

I'm developing a Java application that needs to be easily distributable and doesn't require anything installed on the host system except Java 1.5 or newer.  The Jython interpreter is embedded and used to validate and test Jython code that the user can enter through the swing interface.  It works great right up until the user tries something like:

import string
import re
#...

Of course the issue is that when Jython is installed it know where the Lib directory is, but installing the Jython distribution on any of the host machines is not an option (in fact this app will almost certainly only be able to run as an applet or webstart).

I've tried tricks like jarring up the Lib/ directory and adding it to the classpath which I should have guessed won't automagically work.  In the Jython API the PathPackageManager looks promising, but I admit that I can't figure out how it ties into the interpreter.  It also appears that python.path can help me out, but I don't think that just including the Lib dir and all those files is a very good solution (maybe not even possible with webstart and applet).

I don't mind interrogating a jar file containing all of the necessary source and fiddling with JarEntries and that fun stuff if there's a way that I can get access to the Jython standard imports in a Jar file.  I'm just hoping someone's either done it before or can point me in the right direction in the API docs.  It seems to me, also, that being able to distribute the Lib stuff in a jar would make a lot of people's lives easier.

Thanks,
Mike

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Stuck on standard imports

Jeff Emanuel
If you put Lib in a jar, then you need to make sure
sys.path includes path_to_jar/Lib, probably by setting
the Java system property python.path since you won't
have a jython registry file.

Michael Litherland wrote:

> Hi,
>
> I've searched the documentation and the list archives as well as I could
> and
> though I've seen somewhat similar queries I haven't found any solutions
> yet.
>
> I'm developing a Java application that needs to be easily distributable and
> doesn't require anything installed on the host system except Java 1.5 or
> newer.  The Jython interpreter is embedded and used to validate and test
> Jython code that the user can enter through the swing interface.  It works
> great right up until the user tries something like:
>
> import string
> import re
> #...
>
> Of course the issue is that when Jython is installed it know where the Lib
> directory is, but installing the Jython distribution on any of the host
> machines is not an option (in fact this app will almost certainly only be
> able to run as an applet or webstart).
>
> I've tried tricks like jarring up the Lib/ directory and adding it to the
> classpath which I should have guessed won't automagically work.  In the
> Jython API the PathPackageManager looks promising, but I admit that I can't
> figure out how it ties into the interpreter.  It also appears that
> python.path can help me out, but I don't think that just including the Lib
> dir and all those files is a very good solution (maybe not even possible
> with webstart and applet).
>
> I don't mind interrogating a jar file containing all of the necessary
> source
> and fiddling with JarEntries and that fun stuff if there's a way that I can
> get access to the Jython standard imports in a Jar file.  I'm just hoping
> someone's either done it before or can point me in the right direction in
> the API docs.  It seems to me, also, that being able to distribute the Lib
> stuff in a jar would make a lot of people's lives easier.
>
> Thanks,
> Mike
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Jython-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jython-users

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Stuck on standard imports

Leo User
In reply to this post by Michael Litherland
--- Michael Litherland <[hidden email]>
wrote:

> Hi,
>
> I've searched the documentation and the list
> archives as well as I could and
> though I've seen somewhat similar queries I haven't
> found any solutions yet.
>
> I'm developing a Java application that needs to be
> easily distributable and
> doesn't require anything installed on the host
> system except Java 1.5 or
> newer.  The Jython interpreter is embedded and used
> to validate and test
> Jython code that the user can enter through the
> swing interface.  It works
> great right up until the user tries something like:
>
> import string
> import re
> #...
>
> Of course the issue is that when Jython is installed
> it know where the Lib
> directory is, but installing the Jython distribution
> on any of the host
> machines is not an option (in fact this app will
> almost certainly only be
> able to run as an applet or webstart).
>
> I've tried tricks like jarring up the Lib/ directory
> and adding it to the
> classpath which I should have guessed won't
> automagically work.  In the
> Jython API the PathPackageManager looks promising,
> but I admit that I can't
> figure out how it ties into the interpreter.  It
> also appears that
> python.path can help me out, but I don't think that
> just including the Lib
> dir and all those files is a very good solution
> (maybe not even possible
> with webstart and applet).
>
> I don't mind interrogating a jar file containing all
> of the necessary source
> and fiddling with JarEntries and that fun stuff if
> there's a way that I can
> get access to the Jython standard imports in a Jar
> file.  I'm just hoping
> someone's either done it before or can point me in
> the right direction in
> the API docs.  It seems to me, also, that being able
> to distribute the Lib
> stuff in a jar would make a lot of people's lives
> easier.
>
> Thanks,
> Mike
> >

egads,

this subject seems to come up alot and just this week
too.  I wrote a loader that tries to load the py file
as a resource:
   public static class JSLoader extends PyObject{
        Map<String, PyObject> loadedmods = new
HashMap<String, PyObject>();
        public PyObject find_module(PyObject[] args){
            PyObject rv = load_module(args[0]);
            if(rv != null && rv != Py.None){
                loadedmods.put(args[0].toString(),
rv);
                return this;
            }
            return Py.None;
        }
       
        public PyObject load_module(PyObject modname){
           
            String modstring = modname.toString();
            if(modstring.endsWith(".class"))
                return Py.None;
            if(modstring.startsWith("./"))
                modstring = modstring.substring(2);
            if(loadedmods.containsKey(modstring))
                return loadedmods.get(modstring);
            try{
                ClassLoader cl =
this.getClass().getClassLoader();
                String resource = "Lib/" +
modstring.toString() + ".py";
                java.net.URL url =
cl.getResource(resource);
                if(url != null){
                    return
imp.createFromSource(modname.toString(),
                                           
url.openStream(),
                                           
url.toString());        
                }
            } catch(java.io.IOException io){}
            return Py.None;
        }
    }

I add it after the PySystemState has been initialised:
Py.getSystemState().meta_path.append(importer);

Im not sure if it will work for you, I jared the
application with the jython code and the python libs.
If your just wrapping the Lib in a jar file you may
need to get the jar file as a resource and work from
it there.

-----------
this seems like such a common problem that Im going to
add some options for this very thing to JythonX(unless
there is a switch I don't know about :D).

Maybe something along the lines of:
setTryGetResourceForPyFileLoading(boolean tryget)

and maybe some methods to be able to set different
locations to look for:
addGetResourcePath(String path)

that way you could package your stuff up in different
locations.

leouser





 
____________________________________________________________________________________
No need to miss a message. Get email on-the-go
with Yahoo! Mail for Mobile. Get started.
http://mobile.yahoo.com/mail 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Stuck on standard imports

Stefan Dupont-Christ
In reply to this post by Michael Litherland
This is the way it worked for me:

1. after jar-ing up the Lib/ directory, it looks like this:

> jar -tf jython-lib.jar
META-INF/
META-INF/MANIFEST.MF
Lib/email/base64MIME.py
Lib/email/Charset.py
Lib/email/_compat21.py
Lib/email/_compat22.py
Lib/email/Encoders.py
Lib/email/Errors.py
[...]

2. jython-lib.jar needs to be in the CLASSPATH

3. in jython script I use:

import sys
sys.packageManager.addJar("<path_to>/jython-lib.jar", 1)
if not "<path_to>/jython-lib.jar/Lib" in sys.path:
sys.path.append("<path_to>/jython-lib.jar/Lib")

# now this should work
import string, os

Hope this helps

--Stefan

Michael Litherland wrote:

> Hi,
>
> I've searched the documentation and the list archives as well as I
> could and
> though I've seen somewhat similar queries I haven't found any
> solutions yet.
>
> I'm developing a Java application that needs to be easily
> distributable and
> doesn't require anything installed on the host system except Java 1.5 or
> newer.  The Jython interpreter is embedded and used to validate and test
> Jython code that the user can enter through the swing interface.  It
> works
> great right up until the user tries something like:
>
> import string
> import re
> #...
>
> Of course the issue is that when Jython is installed it know where the
> Lib
> directory is, but installing the Jython distribution on any of the host
> machines is not an option (in fact this app will almost certainly only be
> able to run as an applet or webstart).
>
> I've tried tricks like jarring up the Lib/ directory and adding it to the
> classpath which I should have guessed won't automagically work.  In the
> Jython API the PathPackageManager looks promising, but I admit that I
> can't
> figure out how it ties into the interpreter.  It also appears that
> python.path can help me out, but I don't think that just including the
> Lib
> dir and all those files is a very good solution (maybe not even possible
> with webstart and applet).
>
> I don't mind interrogating a jar file containing all of the necessary
> source
> and fiddling with JarEntries and that fun stuff if there's a way that
> I can
> get access to the Jython standard imports in a Jar file.  I'm just hoping
> someone's either done it before or can point me in the right direction in
> the API docs.  It seems to me, also, that being able to distribute the
> Lib
> stuff in a jar would make a lot of people's lives easier.
>
> Thanks,
> Mike
>
>------------------------------------------------------------------------
>
>-------------------------------------------------------------------------
>Take Surveys. Earn Cash. Influence the Future of IT
>Join SourceForge.net's Techsay panel and you'll get the chance to share your
>opinions on IT & business topics through brief surveys-and earn cash
>http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Jython-users mailing list
>[hidden email]
>https://lists.sourceforge.net/lists/listinfo/jython-users
>  
>


--

Stefan Dupont-Christ
_________________
       
GIP Exyr GmbH
Göttelmannstr. 17
55130 Mainz

Tel: +49 (0) 6131 / 80 124 - 29
Fax: +49 (0) 6131 / 80 124 - 24

E-Mail: [hidden email]
Web: www.gip.com

GIP Exyr GmbH
Geschäftsführer: Dr. Bernd Reifenhäuser  
Handelsregister: HRB  6870 - Amtsgericht Mainz


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Stuck on standard imports

Leo User
Wow,

that looks amazingly simple, Ill have to see if it
works for me and maybe I can ditch the special
importer Ive been using.

thanks!
leouser

--- Stefan Dupont-Christ <[hidden email]> wrote:

> This is the way it worked for me:
>
> 1. after jar-ing up the Lib/ directory, it looks
> like this:
>
> > jar -tf jython-lib.jar
> META-INF/
> META-INF/MANIFEST.MF
> Lib/email/base64MIME.py
> Lib/email/Charset.py
> Lib/email/_compat21.py
> Lib/email/_compat22.py
> Lib/email/Encoders.py
> Lib/email/Errors.py
> [...]
>
> 2. jython-lib.jar needs to be in the CLASSPATH
>
> 3. in jython script I use:
>
> import sys
>
sys.packageManager.addJar("<path_to>/jython-lib.jar",

> 1)
> if not "<path_to>/jython-lib.jar/Lib" in sys.path:
> sys.path.append("<path_to>/jython-lib.jar/Lib")
>
> # now this should work
> import string, os
>
> Hope this helps
>
> --Stefan
>
> Michael Litherland wrote:
>
> > Hi,
> >
> > I've searched the documentation and the list
> archives as well as I
> > could and
> > though I've seen somewhat similar queries I
> haven't found any
> > solutions yet.
> >
> > I'm developing a Java application that needs to be
> easily
> > distributable and
> > doesn't require anything installed on the host
> system except Java 1.5 or
> > newer.  The Jython interpreter is embedded and
> used to validate and test
> > Jython code that the user can enter through the
> swing interface.  It
> > works
> > great right up until the user tries something
> like:
> >
> > import string
> > import re
> > #...
> >
> > Of course the issue is that when Jython is
> installed it know where the
> > Lib
> > directory is, but installing the Jython
> distribution on any of the host
> > machines is not an option (in fact this app will
> almost certainly only be
> > able to run as an applet or webstart).
> >
> > I've tried tricks like jarring up the Lib/
> directory and adding it to the
> > classpath which I should have guessed won't
> automagically work.  In the
> > Jython API the PathPackageManager looks promising,
> but I admit that I
> > can't
> > figure out how it ties into the interpreter.  It
> also appears that
> > python.path can help me out, but I don't think
> that just including the
> > Lib
> > dir and all those files is a very good solution
> (maybe not even possible
> > with webstart and applet).
> >
> > I don't mind interrogating a jar file containing
> all of the necessary
> > source
> > and fiddling with JarEntries and that fun stuff if
> there's a way that
> > I can
> > get access to the Jython standard imports in a Jar
> file.  I'm just hoping
> > someone's either done it before or can point me in
> the right direction in
> > the API docs.  It seems to me, also, that being
> able to distribute the
> > Lib
> > stuff in a jar would make a lot of people's lives
> easier.
> >
> > Thanks,
> > Mike
> >
>
>------------------------------------------------------------------------
> >
>
>-------------------------------------------------------------------------
> >Take Surveys. Earn Cash. Influence the Future of IT
> >Join SourceForge.net's Techsay panel and you'll get
> the chance to share your
> >opinions on IT & business topics through brief
> surveys-and earn cash
>
>http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> >
>
>------------------------------------------------------------------------
> >
> >_______________________________________________
> >Jython-users mailing list
> >[hidden email]
>
>https://lists.sourceforge.net/lists/listinfo/jython-users
> >  
> >
>
>
> --
>
> Stefan Dupont-Christ
> _________________
>
> GIP Exyr GmbH
> Göttelmannstr. 17
> 55130 Mainz
>
> Tel: +49 (0) 6131 / 80 124 - 29
> Fax: +49 (0) 6131 / 80 124 - 24
>
> E-Mail: [hidden email]
> Web: www.gip.com
>
> GIP Exyr GmbH
> Geschäftsführer: Dr. Bernd Reifenhäuser  
> Handelsregister: HRB  6870 - Amtsgericht Mainz
>
>
>
-------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get
> the chance to share your
> opinions on IT & business topics through brief
> surveys-and earn cash
>
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Jython-users mailing list
> [hidden email]
>
https://lists.sourceforge.net/lists/listinfo/jython-users
>



 
____________________________________________________________________________________
TV dinner still cooling?
Check out "Tonight's Picks" on Yahoo! TV.
http://tv.yahoo.com/

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Stuck on standard imports

Michael Litherland
Even simpler - this seems to work:

System.setProperty("python.path", "path/to/jythonlib.jar/Lib");

Mike

On 3/28/07, Leo User <[hidden email]> wrote:
Wow,

that looks amazingly simple, Ill have to see if it
works for me and maybe I can ditch the special
importer Ive been using.

thanks!
leouser

--- Stefan Dupont-Christ <[hidden email]> wrote:

> This is the way it worked for me:
>
> 1. after jar-ing up the Lib/ directory, it looks
> like this:
>
> > jar -tf jython-lib.jar
> META-INF/
> META-INF/MANIFEST.MF
> Lib/email/base64MIME.py
> Lib/email/Charset.py
> Lib/email/_compat21.py
> Lib/email/_compat22.py
> Lib/email/Encoders.py
> Lib/email/Errors.py
> [...]
>
> 2. jython-lib.jar needs to be in the CLASSPATH
>
> 3. in jython script I use:
>
> import sys
>
sys.packageManager.addJar("<path_to>/jython-lib.jar",
> 1)
> if not "<path_to>/jython-lib.jar/Lib" in sys.path:
> sys.path.append("<path_to>/jython-lib.jar/Lib")
>
> # now this should work
> import string, os
>
> Hope this helps
>
> --Stefan
>
> Michael Litherland wrote:
>
> > Hi,
> >
> > I've searched the documentation and the list
> archives as well as I
> > could and
> > though I've seen somewhat similar queries I
> haven't found any
> > solutions yet.
> >
> > I'm developing a Java application that needs to be
> easily

> > distributable and
> > doesn't require anything installed on the host
> system except Java 1.5 or
> > newer.  The Jython interpreter is embedded and
> used to validate and test
> > Jython code that the user can enter through the
> swing interface.  It
> > works
> > great right up until the user tries something
> like:
> >
> > import string
> > import re
> > #...
> >
> > Of course the issue is that when Jython is
> installed it know where the
> > Lib
> > directory is, but installing the Jython
> distribution on any of the host
> > machines is not an option (in fact this app will
> almost certainly only be
> > able to run as an applet or webstart).
> >
> > I've tried tricks like jarring up the Lib/
> directory and adding it to the

> > classpath which I should have guessed won't
> automagically work.  In the
> > Jython API the PathPackageManager looks promising,
> but I admit that I
> > can't
> > figure out how it ties into the interpreter.  It
> also appears that
> > python.path can help me out, but I don't think
> that just including the
> > Lib
> > dir and all those files is a very good solution
> (maybe not even possible
> > with webstart and applet).
> >
> > I don't mind interrogating a jar file containing
> all of the necessary
> > source
> > and fiddling with JarEntries and that fun stuff if
> there's a way that
> > I can
> > get access to the Jython standard imports in a Jar
> file.  I'm just hoping
> > someone's either done it before or can point me in
> the right direction in
> > the API docs.  It seems to me, also, that being
> able to distribute the
> > Lib
> > stuff in a jar would make a lot of people's lives
> easier.
> >
> > Thanks,
> > Mike
> >
>
>------------------------------------------------------------------------
> >
>
>-------------------------------------------------------------------------
> >Take Surveys. Earn Cash. Influence the Future of IT
> >Join SourceForge.net's Techsay panel and you'll get
> the chance to share your
> >opinions on IT & business topics through brief
> surveys-and earn cash
>
>http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> >
>
>------------------------------------------------------------------------
> >
> >_______________________________________________
> >Jython-users mailing list
> > [hidden email]
>
>https://lists.sourceforge.net/lists/listinfo/jython-users
> >
> >
>
>
> --
>
> Stefan Dupont-Christ
> _________________
>
> GIP Exyr GmbH
> Göttelmannstr. 17
> 55130 Mainz
>
> Tel: +49 (0) 6131 / 80 124 - 29
> Fax: +49 (0) 6131 / 80 124 - 24
>
> E-Mail: [hidden email]
> Web: www.gip.com
>
> GIP Exyr GmbH
> Geschäftsführer: Dr. Bernd Reifenhäuser
> Handelsregister: HRB  6870 - Amtsgericht Mainz
>
>
>
-------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get
> the chance to share your
> opinions on IT & business topics through brief
> surveys-and earn cash
>
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Jython-users mailing list
> [hidden email]
>
https://lists.sourceforge.net/lists/listinfo/jython-users
>




____________________________________________________________________________________
TV dinner still cooling?
Check out "Tonight's Picks" on Yahoo! TV.
http://tv.yahoo.com/

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Stuck on standard imports

Leo User
--- Michael Litherland <[hidden email]>
wrote:

> Even simpler - this seems to work:
>
> System.setProperty("python.path",
> "path/to/jythonlib.jar/Lib");
>
> Mike

Im going to be amazingly surprised if this will work
for the complete-jar solution, but Ill give it a shot.
   

It still would be nice if there were some simple clear
API methods that did the job instead of having to mess
around with environment variables and internal data
structures.  Its good that there are things that work
but everyone seems to be finding different ways of
doing the job.  Though there are some methods in
PySystemState that appear to do something to help,
add_classdir, etc.. .

leouser


>
> On 3/28/07, Leo User <[hidden email]> wrote:
> >
> > Wow,
> >
> > that looks amazingly simple, Ill have to see if it
> > works for me and maybe I can ditch the special
> > importer Ive been using.
> >
> > thanks!
> > leouser
> >
> > --- Stefan Dupont-Christ <[hidden email]> wrote:
> >
> > > This is the way it worked for me:
> > >
> > > 1. after jar-ing up the Lib/ directory, it looks
> > > like this:
> > >
> > > > jar -tf jython-lib.jar
> > > META-INF/
> > > META-INF/MANIFEST.MF
> > > Lib/email/base64MIME.py
> > > Lib/email/Charset.py
> > > Lib/email/_compat21.py
> > > Lib/email/_compat22.py
> > > Lib/email/Encoders.py
> > > Lib/email/Errors.py
> > > [...]
> > >
> > > 2. jython-lib.jar needs to be in the CLASSPATH
> > >
> > > 3. in jython script I use:
> > >
> > > import sys
> > >
> >
>
sys.packageManager.addJar("<path_to>/jython-lib.jar",

> > > 1)
> > > if not "<path_to>/jython-lib.jar/Lib" in
> sys.path:
> > > sys.path.append("<path_to>/jython-lib.jar/Lib")
> > >
> > > # now this should work
> > > import string, os
> > >
> > > Hope this helps
> > >
> > > --Stefan
> > >
> > > Michael Litherland wrote:
> > >
> > > > Hi,
> > > >
> > > > I've searched the documentation and the list
> > > archives as well as I
> > > > could and
> > > > though I've seen somewhat similar queries I
> > > haven't found any
> > > > solutions yet.
> > > >
> > > > I'm developing a Java application that needs
> to be
> > > easily
> > > > distributable and
> > > > doesn't require anything installed on the host
> > > system except Java 1.5 or
> > > > newer.  The Jython interpreter is embedded and
> > > used to validate and test
> > > > Jython code that the user can enter through
> the
> > > swing interface.  It
> > > > works
> > > > great right up until the user tries something
> > > like:
> > > >
> > > > import string
> > > > import re
> > > > #...
> > > >
> > > > Of course the issue is that when Jython is
> > > installed it know where the
> > > > Lib
> > > > directory is, but installing the Jython
> > > distribution on any of the host
> > > > machines is not an option (in fact this app
> will
> > > almost certainly only be
> > > > able to run as an applet or webstart).
> > > >
> > > > I've tried tricks like jarring up the Lib/
> > > directory and adding it to the
> > > > classpath which I should have guessed won't
> > > automagically work.  In the
> > > > Jython API the PathPackageManager looks
> promising,
> > > but I admit that I
> > > > can't
> > > > figure out how it ties into the interpreter.
> It
> > > also appears that
> > > > python.path can help me out, but I don't think
> > > that just including the
> > > > Lib
> > > > dir and all those files is a very good
> solution
> > > (maybe not even possible
> > > > with webstart and applet).
> > > >
> > > > I don't mind interrogating a jar file
> containing
> > > all of the necessary
> > > > source
> > > > and fiddling with JarEntries and that fun
> stuff if
> > > there's a way that
> > > > I can
> > > > get access to the Jython standard imports in a
> Jar
> > > file.  I'm just hoping
> > > > someone's either done it before or can point
> me in
> > > the right direction in
> > > > the API docs.  It seems to me, also, that
> being
> > > able to distribute the
> > > > Lib
> > > > stuff in a jar would make a lot of people's
> lives
> > > easier.
> > > >
> > > > Thanks,
> > > > Mike
> > > >
> > >
> >
>
>------------------------------------------------------------------------
> > > >
> > >
> >
>
>-------------------------------------------------------------------------
> > > >Take Surveys. Earn Cash. Influence the Future
> of IT
> > > >Join SourceForge.net's Techsay panel and you'll
> get
> > > the chance to share your
> > > >opinions on IT & business topics through brief
> > > surveys-and earn cash
> > >
> >
>
>http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> > > >
> > >
> >
>
>------------------------------------------------------------------------
> > > >
> > > >_______________________________________________
> > > >Jython-users mailing list
> > > >[hidden email]
> > >
> >
>
>https://lists.sourceforge.net/lists/listinfo/jython-users
> > > >
> > > >
> > >
> > >
> > > --
> > >
> > > Stefan Dupont-Christ
> > > _________________
> > >
> > > GIP Exyr GmbH
> > > Göttelmannstr. 17
> > > 55130 Mainz
> > >
> > > Tel: +49 (0) 6131 / 80 124 - 29
> > > Fax: +49 (0) 6131 / 80 124 - 24
> > >
> > > E-Mail: [hidden email]
> > > Web: www.gip.com
> > >
> > > GIP Exyr GmbH
> > > Geschäftsführer: Dr. Bernd Reifenhäuser
> > > Handelsregister: HRB  6870 - Amtsgericht Mainz
> > >
> > >
> > >
> >
>
-------------------------------------------------------------------------
> > > Take Surveys. Earn Cash. Influence the Future of
> IT
> > > Join SourceForge.net's Techsay panel and you'll
> get
> > > the chance to share your
> > > opinions on IT & business topics through brief
>
=== message truncated ===



 
____________________________________________________________________________________
Sucker-punch spam with award-winning protection.
Try the free Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/features_spam.html

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Stuck on standard imports

Michael Litherland


On 3/28/07, Leo User <[hidden email]> wrote:
--- Michael Litherland <[hidden email]>
wrote:

> Even simpler - this seems to work:
>
> System.setProperty("python.path",
> "path/to/jythonlib.jar/Lib");
>
> Mike

Im going to be amazingly surprised if this will work
for the complete-jar solution, but Ill give it a shot.


It still would be nice if there were some simple clear
API methods that did the job instead of having to mess
around with environment variables and internal data
structures.  Its good that there are things that work
but everyone seems to be finding different ways of
doing the job.  Though there are some methods in
PySystemState that appear to do something to help,
add_classdir, etc.. .

leouser

This is the exact code I'm using:


        String[] paths = System.getProperty("java.class.path").
                split(System.getProperty("path.separator"));
        boolean foundLib = false;
        for (int i = 0; i < paths.length; i++) {
            if (paths[i].contains("jythonlib")) {
                System.setProperty("python.path", paths[i]+"/Lib");
                System.out.println("Using pythonlib at "+paths[i]+"/Lib");
                foundLib = true;
            }
        }
        if (!foundLib) {
            throw new RuntimeException("Required library jar not found!");
        }

If I comment out the setProperty line it fails - works otherwise.

Mike 

>

> On 3/28/07, Leo User <[hidden email]> wrote:
> >
> > Wow,
> >
> > that looks amazingly simple, Ill have to see if it
> > works for me and maybe I can ditch the special
> > importer Ive been using.
> >
> > thanks!
> > leouser
> >
> > --- Stefan Dupont-Christ <[hidden email]> wrote:
> >
> > > This is the way it worked for me:
> > >
> > > 1. after jar-ing up the Lib/ directory, it looks
> > > like this:
> > >
> > > > jar -tf jython-lib.jar
> > > META-INF/
> > > META-INF/MANIFEST.MF
> > > Lib/email/base64MIME.py
> > > Lib/email/Charset.py
> > > Lib/email/_compat21.py
> > > Lib/email/_compat22.py
> > > Lib/email/Encoders.py
> > > Lib/email/Errors.py
> > > [...]
> > >
> > > 2. jython-lib.jar needs to be in the CLASSPATH
> > >
> > > 3. in jython script I use:
> > >
> > > import sys
> > >
> >
>
sys.packageManager.addJar("<path_to>/jython-lib.jar",

> > > 1)
> > > if not "<path_to>/jython-lib.jar/Lib" in
> sys.path :
> > > sys.path.append("<path_to>/jython-lib.jar/Lib")
> > >
> > > # now this should work
> > > import string, os
> > >
> > > Hope this helps
> > >
> > > --Stefan
> > >
> > > Michael Litherland wrote:
> > >
> > > > Hi,
> > > >
> > > > I've searched the documentation and the list
> > > archives as well as I
> > > > could and
> > > > though I've seen somewhat similar queries I
> > > haven't found any
> > > > solutions yet.
> > > >
> > > > I'm developing a Java application that needs
> to be
> > > easily
> > > > distributable and
> > > > doesn't require anything installed on the host
> > > system except Java 1.5 or
> > > > newer.  The Jython interpreter is embedded and
> > > used to validate and test
> > > > Jython code that the user can enter through
> the
> > > swing interface.  It
> > > > works
> > > > great right up until the user tries something
> > > like:
> > > >
> > > > import string
> > > > import re
> > > > #...
> > > >
> > > > Of course the issue is that when Jython is
> > > installed it know where the
> > > > Lib
> > > > directory is, but installing the Jython
> > > distribution on any of the host
> > > > machines is not an option (in fact this app
> will
> > > almost certainly only be
> > > > able to run as an applet or webstart).
> > > >
> > > > I've tried tricks like jarring up the Lib/
> > > directory and adding it to the
> > > > classpath which I should have guessed won't
> > > automagically work.  In the
> > > > Jython API the PathPackageManager looks
> promising,
> > > but I admit that I
> > > > can't
> > > > figure out how it ties into the interpreter.
> It
> > > also appears that
> > > > python.path can help me out, but I don't think
> > > that just including the
> > > > Lib
> > > > dir and all those files is a very good
> solution
> > > (maybe not even possible
> > > > with webstart and applet).
> > > >
> > > > I don't mind interrogating a jar file
> containing
> > > all of the necessary
> > > > source
> > > > and fiddling with JarEntries and that fun
> stuff if
> > > there's a way that
> > > > I can
> > > > get access to the Jython standard imports in a

> Jar
> > > file.  I'm just hoping
> > > > someone's either done it before or can point
> me in
> > > the right direction in
> > > > the API docs.  It seems to me, also, that
> being
> > > able to distribute the
> > > > Lib
> > > > stuff in a jar would make a lot of people's
> lives

> > > easier.
> > > >
> > > > Thanks,
> > > > Mike
> > > >
> > >
> >
>
>------------------------------------------------------------------------
> > > >
> > >
> >
>
>-------------------------------------------------------------------------
> > > >Take Surveys. Earn Cash. Influence the Future
> of IT
> > > >Join SourceForge.net's Techsay panel and you'll
> get
> > > the chance to share your
> > > >opinions on IT & business topics through brief
> > > surveys-and earn cash
> > >
> >
>
>http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> > > >
> > >
> >
>
>------------------------------------------------------------------------
> > > >
> > > >_______________________________________________
> > > >Jython-users mailing list
> > > >[hidden email]
> > >
> >
>
> https://lists.sourceforge.net/lists/listinfo/jython-users
> > > >
> > > >
> > >
> > >
> > > --
> > >
> > > Stefan Dupont-Christ
> > > _________________
> > >
> > > GIP Exyr GmbH
> > > Göttelmannstr. 17
> > > 55130 Mainz
> > >
> > > Tel: +49 (0) 6131 / 80 124 - 29
> > > Fax: +49 (0) 6131 / 80 124 - 24

> > >
> > > E-Mail: [hidden email]
> > > Web: www.gip.com
> > >
> > > GIP Exyr GmbH
> > > Geschäftsführer: Dr. Bernd Reifenhäuser
> > > Handelsregister: HRB  6870 - Amtsgericht Mainz
> > >
> > >
> > >
> >
>
-------------------------------------------------------------------------
> > > Take Surveys. Earn Cash. Influence the Future of
> IT
> > > Join SourceForge.net's Techsay panel and you'll
> get
> > > the chance to share your
> > > opinions on IT & business topics through brief
>
=== message truncated ===




____________________________________________________________________________________
Sucker-punch spam with award-winning protection.
Try the free Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/features_spam.html

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Stuck on standard imports

oti-3
Hi,

maybe even simpler:
 - install jython selecting the 'standalone' mode
 - as a result, you get a jython.jar with the /Lib files included
 - if you add this to the classpath of your app, standard imports will work.

best wishes,
Oti.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Stuck on standard imports

Michael Litherland
Hi Oti,

That's good to know.  It would be nice to see that mentioned on this page: http://jython.org/Project/installation.html Possibly it would also be good to make that option a little more clear in the GUI installer.

Just some thoughts, thanks!

Mike

On 3/30/07, Oti <[hidden email]> wrote:
Hi,

maybe even simpler:
- install jython selecting the 'standalone' mode
- as a result, you get a jython.jar with the /Lib files included
- if you add this to the classpath of your app, standard imports will work.

best wishes,
Oti.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Stuck on standard imports

fwierzbicki@gmail.com
On 3/30/07, Michael Litherland <[hidden email]> wrote:
> Hi Oti,
>
> That's good to know.  It would be nice to see that mentioned on this page:
> http://jython.org/Project/installation.html Possibly it
I will take this task -- there are several items I want to fix on the
website -- I'll try to get to them this weekend.

-Frank

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users