wood burning stoves 2.0*
The moose likes Jython/Python and the fly likes file not found when calling execfile function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "file not found when calling execfile function" Watch "file not found when calling execfile function" New topic

file not found when calling execfile function

Dave Patrick

Joined: May 23, 2011
Posts: 2
I am trying to execute the following code from Java:

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?

Matt Cartwright
Ranch Hand

Joined: Aug 25, 2008
Posts: 149

'execfile(String arg0)' searches the current working directory, you need to specify the absolute path and I always add the extension (.py)...

you could open the file as a java.io.InputStream and pass it to 'execfile(InputStream arg0)'

It is sorta covered in the JavaRanch Style Guide.
subject: file not found when calling execfile function
Similar Threads
AttributeError when calling pyhton scripts from java class
Help - How to I tell java where my jython.py script is located in the Directory
How to call a Python method form Java class
Calling python function from java
Executing Jython script from java and accessing resulting object