From: dstarr <sta...@ho...> - 2011-05-26 15:29:01
|
Hi, I am trying to execute the following code from Java: PythonInterpreter pyInter = new PythonInterpreter(); pyInter.execfile("SendGridEnvelope.py"); I have a python script called SendGridEnvelope.py that gets packaged in my WAR under WEB-INF/classes. I keep getting a file not found exception because the execfile function is looking for the Python script under my Jboss/bin directory. I am using Jython by the way. Does anyone know why the execfile method is looking for the python script in the Jboss/bin dir and how to change this? Thanks, David -- View this message in context: http://old.nabble.com/file-not-found-when-calling-execfile-function-tp31703044p31703044.html Sent from the jython-users mailing list archive at Nabble.com. |
From: David H. <Dav...@sa...> - 2011-05-26 16:12:40
|
I'll give a wild guess, others can correct me if I'm wrong. The execfile() method is looking in the Jboss/bin directory because that is the current directory for the JVM that is running JBoss. I don't think you can change the current working directory of your running JBoss. One possible solution to your problem: InputStream inStr = this.getClass().getClassLoader().getResourceAsStream("SendGridEnvelope.py"); pyInter.execfile(inStr, "SendGridEnvelope.py"); (I checked, and there is a PythonInterpreter.execfile() method that takes an InputStream and a name as a parameter. The name is probably only used in stack traces, etc., not to locate the file.) > -----Original Message----- > From: dstarr [mailto:sta...@ho...] > Sent: Thursday, May 26, 2011 11:29 AM > To: jyt...@li... > Subject: [Jython-users] file not found when calling execfile function > > > Hi, > I am trying to execute the following code from Java: > > PythonInterpreter pyInter = new PythonInterpreter(); > pyInter.execfile("SendGridEnvelope.py"); > > I have a python script called SendGridEnvelope.py that gets packaged in my > WAR under WEB-INF/classes. > > I keep getting a file not found exception because the execfile function is > looking for the Python script under my Jboss/bin directory. I am using Jython > by the way. > > Does anyone know why the execfile method is looking for the python script > in the Jboss/bin dir and how to change this? > > Thanks, > David > -- > View this message in context: http://old.nabble.com/file-not-found-when- > calling-execfile-function-tp31703044p31703044.html > Sent from the jython-users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------------ > vRanger cuts backup time in half-while increasing security. > With the market-leading solution for virtual backup and recovery, you get > blazing-fast, flexible, and affordable data protection. > Download your free trial now. > http://p.sf.net/sfu/quest-d2dcopy1 > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |
From: dstarr <sta...@ho...> - 2011-05-26 16:26:59
|
thanks David, i'll give it a try. David Handy-3 wrote: > > I'll give a wild guess, others can correct me if I'm wrong. > > The execfile() method is looking in the Jboss/bin directory because that > is the current directory for the JVM that is running JBoss. > I don't think you can change the current working directory of your running > JBoss. > > One possible solution to your problem: > > InputStream inStr = > this.getClass().getClassLoader().getResourceAsStream("SendGridEnvelope.py"); > pyInter.execfile(inStr, "SendGridEnvelope.py"); > > (I checked, and there is a PythonInterpreter.execfile() method that takes > an InputStream and a name as a parameter. The name is probably only used > in stack traces, etc., not to locate the file.) > > >> -----Original Message----- >> From: dstarr [mailto:sta...@ho...] >> Sent: Thursday, May 26, 2011 11:29 AM >> To: jyt...@li... >> Subject: [Jython-users] file not found when calling execfile function >> >> >> Hi, >> I am trying to execute the following code from Java: >> >> PythonInterpreter pyInter = new PythonInterpreter(); >> pyInter.execfile("SendGridEnvelope.py"); >> >> I have a python script called SendGridEnvelope.py that gets packaged in >> my >> WAR under WEB-INF/classes. >> >> I keep getting a file not found exception because the execfile function >> is >> looking for the Python script under my Jboss/bin directory. I am using >> Jython >> by the way. >> >> Does anyone know why the execfile method is looking for the python script >> in the Jboss/bin dir and how to change this? >> >> Thanks, >> David >> -- >> View this message in context: http://old.nabble.com/file-not-found-when- >> calling-execfile-function-tp31703044p31703044.html >> Sent from the jython-users mailing list archive at Nabble.com. >> >> >> ------------------------------------------------------------------------------ >> vRanger cuts backup time in half-while increasing security. >> With the market-leading solution for virtual backup and recovery, you get >> blazing-fast, flexible, and affordable data protection. >> Download your free trial now. >> http://p.sf.net/sfu/quest-d2dcopy1 >> _______________________________________________ >> Jython-users mailing list >> Jyt...@li... >> https://lists.sourceforge.net/lists/listinfo/jython-users > > > > ------------------------------------------------------------------------------ > vRanger cuts backup time in half-while increasing security. > With the market-leading solution for virtual backup and recovery, > you get blazing-fast, flexible, and affordable data protection. > Download your free trial now. > http://p.sf.net/sfu/quest-d2dcopy1 > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > -- View this message in context: http://old.nabble.com/file-not-found-when-calling-execfile-function-tp31703044p31709651.html Sent from the jython-users mailing list archive at Nabble.com. |
From: dstarr <sta...@ho...> - 2011-05-26 19:26:45
|
I am still having an issue finding the Python script(s). Here is what i've tried. My scripts that I want to add to the sys.path are packaged in an EAR file under a different location(/blah/jboss/deploy/shared/blah.ear) than my jboss dir. Is that going to be an issue? pyInter.exec("import sys"); String earPath = AppProps.instance().getProperty(AppProps.KEY_CNS_EAR_PATH); pyInter.set("earPath", earPath); pyInter.exec("sys.path.append(earPath)"); pyInter.exec("x = sys.path"); PyObject sysPath = pyInter.get("x"); pyInter.execfile("SendGridEnvelope.py"); any help would be greatly appreciated. This is killing me. -- View this message in context: http://old.nabble.com/file-not-found-when-calling-execfile-function-tp31703044p31711113.html Sent from the jython-users mailing list archive at Nabble.com. |
From: Pierre T. <pie...@gm...> - 2011-05-27 20:38:17
|
2011/5/26 dstarr <sta...@ho...> > > Hi, > I am trying to execute the following code from Java: > > PythonInterpreter pyInter = new PythonInterpreter(); > pyInter.execfile("SendGridEnvelope.py"); > > I have a python script called SendGridEnvelope.py that gets packaged in my > WAR under WEB-INF/classes. > > I think this goes in the lib directory. -- A+ ------------- Pierre My blog and profile (http://pierrethibault.posterous.com)<http://pierrethibault.posterous.com> YouTube page (http://www.youtube.com/user/tubetib)<http://www.youtube.com/user/tubetib> Twitter (http://twitter.com/pierreth2) <http://twitter.com/pierreth2> |
From: Josh J. <jun...@gm...> - 2011-05-28 13:48:38
|
Sorry I never got back to you, hope you were able to figure out this issue, or at least a workaround. I have never tried to use scripts that were included in an EAR file in my sys.path, so I really am not sure if that would work. I know that a JAR should work just fine...never tried an EAR myself though. Can't you unpack the JAR that is contained within the EAR file and put it in the sys.path? That should work, right? Are the scripts within a JAR file inside the EAR? Anyone else on the list ever tried to use PythonInterpreter to work with scripts that are packaged within an EAR? Thanks Josh Juneau jun...@gm... http://jj-blogger.blogspot.com http://www.jythonbook.com Oracle PL/SQL Recipes - http://www.apress.com/9781430232070 On Thu, May 26, 2011 at 2:19 PM, David Starr <sta...@ho...>wrote: > My scripts that I want to add to the sys.path are packaged in an EAR > file. Is that going to be an issue? > > pyInter.exec("import sys"); > String earPath = > AppProps.instance().getProperty(AppProps.KEY_CNS_EAR_PATH); > pyInter.set("earPath", earPath); > pyInter.exec("sys.path.append(earPath)"); > pyInter.exec("x = sys.path"); > PyObject sysPath = pyInter.get("x"); > pyInter.execfile("SendGridEnvelope.py"); > > any help would be greatly appreciated. This is killing me. > > Thanks, > David > > ------------------------------ > Date: Thu, 26 May 2011 11:27:50 -0500 > Subject: Re: [Jython-users] file not found when calling execfile function > From: jun...@gm... > To: sta...@ho... > > Sorry about that, meant to reply-all on that message. Good luck! > > Josh Juneau > jun...@gm... > http://jj-blogger.blogspot.com > http://www.jythonbook.com > Oracle PL/SQL Recipes - http://www.apress.com/9781430232070 > > > > > On Thu, May 26, 2011 at 11:11 AM, David Starr <sta...@ho...>wrote: > > thanks Josh, i will check it out. you're the man! > > ------------------------------ > Date: Thu, 26 May 2011 10:45:30 -0500 > Subject: Re: [Jython-users] file not found when calling execfile function > From: jun...@gm... > To: sta...@ho... > > David- > > Jython will look on your sys.path for the module. Therefore, you need to > be sure that SendGridEnvelope.py is somewhere on your sys.path. Please read > Chapter 8 of the Jythonbook for more information: > http://www.jython.org/jythonbook/en/1.0/ModulesPackages.html#module-search-path-and-loading > > Hope this helps! > > Josh Juneau > jun...@gm... > http://jj-blogger.blogspot.com > http://www.jythonbook.com > Oracle PL/SQL Recipes - http://www.apress.com/9781430232070 > > > > > On Thu, May 26, 2011 at 10:28 AM, dstarr <sta...@ho...>wrote: > > > Hi, > I am trying to execute the following code from Java: > > PythonInterpreter pyInter = new PythonInterpreter(); > pyInter.execfile("SendGridEnvelope.py"); > > I have a python script called SendGridEnvelope.py that gets packaged in my > WAR under WEB-INF/classes. > > I keep getting a file not found exception because the execfile function is > looking for the Python script under my Jboss/bin directory. I am using > Jython by the way. > > Does anyone know why the execfile method is looking for the python script > in > the Jboss/bin dir and how to change this? > > Thanks, > David > -- > View this message in context: > http://old.nabble.com/file-not-found-when-calling-execfile-function-tp31703044p31703044.html > Sent from the jython-users mailing list archive at Nabble.com. > > > > ------------------------------------------------------------------------------ > vRanger cuts backup time in half-while increasing security. > With the market-leading solution for virtual backup and recovery, > you get blazing-fast, flexible, and affordable data protection. > Download your free trial now. > http://p.sf.net/sfu/quest-d2dcopy1 > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > > > |
From: Alan K. <jyt...@xh...> - 2011-06-18 15:19:24
|
[dstarr] > I have a python script called SendGridEnvelope.py that gets packaged in my > WAR under WEB-INF/classes. > > I keep getting a file not found exception because the execfile function is > looking for the Python script under my Jboss/bin directory. I am using > Jython by the way. > > Does anyone know why the execfile method is looking for the python script in > the Jboss/bin dir and how to change this? You need to find the path of the *relative to the context root of the application*. You can see example java source that does that here https://fisheye3.atlassian.com/browse/jython/trunk/jython/src/com/xhaus/modjy/ModjyJServlet.java?hb=true#to192 Should be straightforward to translate to jython. Alan. |