File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Jython/Python and the fly likes Jython use in a web-app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Jython use in a web-app" Watch "Jython use in a web-app" New topic
Author

Jython use in a web-app

Roger Studner
Greenhorn

Joined: Aug 26, 2005
Posts: 6
I have the following piece of code:
public static void executeJob(Job job) throws Exception {
PythonInterpreter pyi = new PythonInterpreter();
pyi.set("job", job);pyi.execfile(EngineUtil.class.getResourceAsStream("JobRunner.py"));
pyi.execfile(EngineUtil.class.getResourceAsStream("StepFactory.py"));
pyi.exec(job.getExecutionScript());
}

The 'execution script' starts with that line:
from com.company.blah.blah import *

When I run it from the command line in a java app with a main (with all relevant stuff on the classpath) everything works.

When I try to run the exact same piece of code inside a web-app (therefore all class files and jars are deployed to /project/WEB-INF (jython.jar in lib, classes in WEB-INF/classes of course).

I got the error:
Traceback (innermost last):
File "<iostream>", line 2, in ?
ImportError: no module named com

at org.python.core.Py.ImportError(Py.java:193)
at org.python.core.imp.import_first(imp.java:523)
at org.python.core.imp.import_name(imp.java:592)
at org.python.core.imp.importName(imp.java:625)
at org.python.core.ImportFunction.load(__builtin__.java:1006)
at org.python.core.ImportFunction.__call__(__builtin__.java:999)
at org.python.core.PyObject.__cal

etc etc.

Why, in a web-app deployment, can the python interpreter not find any of the classes to import?

Any ideas?

Thanks,
Roger
oreoferret@gmail.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jython use in a web-app