Help - How to I tell java where my jython.py script is located in the Directory
Kay Collins
Greenhorn
Joined: Nov 13, 2002
Posts: 2
posted
0
Hi, I need some help with handling my jython script and executing them from java. I compile java and then try to run: java -classpath C:\projects\nginstall\java\src\com\somewhere\gui;C:\jython-2.1\jython;C:\projects\nginstll\Modules\apache TestImport Exception in thread "main" Traceback (innermost last): (no code object) at line 0 I have a test.py located: C\projects\nginstall\modules\apache I have my TestImport.java located: C:\projects\nginstall\scr\com\somewhere\gui This is my java code: ################################### import org.python.core.*; import org.python.util.*; class TestImport{ public static void main(String[] args){
PySystemState.initialize(); PythonInterpreter interp = new PythonInterpreter(); interp.execfile("test.py"); System.out.println("testing"); } } ############### I compile java and then try to run: java -classpath C:\projects\nginstall\java\src\come\something\gui;C:\jython-2.1\jython;C:\projects\nginstll\Modules\apache TestImport Exception in thread "main" Traceback (innermost last): (no code object) at line 0 IOError: File not found - test.py (The system cannot find the file specified)
Tom Purl
Ranch Hand
Joined: May 24, 2002
Posts: 104
posted
0
A few suggestions: 1. Does the execfile method of the PythonInterpreter object allow you to pass it a File object? If if did, then you could do some validation of your file to make sure that it exists. 2. Instead of trying to run .py files from your java class, why not convert your .py file into a .class file using the jythonc program? In that way, you could instantiate your jython class as if it were a java class. Hope that helps! Tom
Tom Purl<br />SCJP 1.4
Kay Collins
Greenhorn
Joined: Nov 13, 2002
Posts: 2
posted
0
Hi Tom I can now successfully run my .py script but I think I will give your second suggestion a try because I need to pass in arguments. Thanks, Kay
subject: Help - How to I tell java where my jython.py script is located in the Directory