This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help - How to I tell java where my jython.py script is located in the Directory

 
Kay Collins
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kay Collins
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic