Can you execfile() scripts inside a jar?

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

Can you execfile() scripts inside a jar?

Steve Yegge
This thread seems to suggest that it's possible:


But I've tried various incantations with no luck.

My scripts are in a jar file on my classpath.  I've ensured that
the absolute path to the jar is added to sys.path, but when I
call myPythonInterpreter.execfile("/any/path/foo.py"), it throws
an IOError complaining file not found, and it does not appear
to be looking in jars in the classpath or in sys.path -- it's always
checking the path relative to the Java process current directory.

Should I just slurp the contents of the file from the jar and pass
it to exec(), instead?

-steve

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: Can you execfile() scripts inside a jar?

Jeff Emanuel

Try PythonInterpreter.execfile(InputStream).  You can get an InputStream for reading an entry from a jar,
eg. http://stackoverflow.com/questions/3369794/how-to-a-read-file-from-jar-in-java



On 10/20/2014 6:40 PM, Steve Yegge wrote:
This thread seems to suggest that it's possible:


But I've tried various incantations with no luck.

My scripts are in a jar file on my classpath.  I've ensured that
the absolute path to the jar is added to sys.path, but when I
call myPythonInterpreter.execfile("/any/path/foo.py"), it throws
an IOError complaining file not found, and it does not appear
to be looking in jars in the classpath or in sys.path -- it's always
checking the path relative to the Java process current directory.

Should I just slurp the contents of the file from the jar and pass
it to exec(), instead?

-steve


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho


_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users