wood burning stoves*
The moose likes Java in General and the fly likes Embedding Jython in JAVA Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Embedding Jython in JAVA Application" Watch "Embedding Jython in JAVA Application" New topic

Embedding Jython in JAVA Application

Nee Kat
Ranch Hand

Joined: Jan 27, 2004
Posts: 37
I have written a program in which Jython code is executed to query a database and result is converted to a String and then displayed.

The problem I am facing is that the criteria for the query is a String in java and I have to pass that variable to Jython code before the query is processed. Here is the code:

public class SimpleEmbedded {
public static void main(String []args)
throws PyException
PythonInterpreter interp =new PythonInterpreter();

String ip_address = "";

interp.exec("import xmlrpclib");

interp.exec("fathomServer = xmlrpclib.Server(\"http://fathom.software.att.com:8000\" )");
interp.exec("reply = fathomServer.ipWhois(");
PyObject x = interp.get("reply");
String fathom = x.toString();

Now in the code the query ipWhois needs an IP Address as input. Right now it is hard coded and working fine but I need to pass a variable there.

I have not been able to find a way to replace hardcoded IP Address with a string variable.

So I need a way to pass java variable to jython.
Please help?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

interp.exec("reply = fathomServer.ipWhois(" + ip_address + ")");

[Jess in Action][AskingGoodQuestions]
Nee Kat
Ranch Hand

Joined: Jan 27, 2004
Posts: 37
Thanks alot!
It worked.
I agree. Here's the link: http://aspose.com/file-tools
subject: Embedding Jython in JAVA Application
Similar Threads
Help - How to I tell java where my jython.py script is located in the Directory
file not found when calling execfile function
Calling python function from java
Executing Jython script from java and accessing resulting object