views:

65

answers:

2

Hi all!

I have written python scripts that use scrapy,nltk and simplejson in my project but i need to run them from java as my mentor wants to deploy them on a server and i have very less time to do this.I took a glance at runtime.exec() in java and jython, needless to say that running system commands from java doesn't look simple either.

So I would like to know if running the python scripts from java as system command -'python example.py ' using runtime.exec() or alternatively using jython would be more simpler and actually feasible or whether there is a simpler workaround .It would also be great to know if anyone had run python code that uses nltk from java using Jython and whether they encountered any problems.Please help me as I have to do this as asap.Any thoughts and suggestions regarding this are welcome.

Thanking in advance!!

+1  A: 

The Jepp project lets you call python scripts from Java. It provides an easy mechanism to pass variables into a script and extract values back. I've used on a few projects with good success

Robert Christie
thanks for the quick reply....:) will look into that
pythonisgr8
A: 

Hi Robert!! i have tried using Jepp,but am stuck with a problem.the following simple code is giving these errors at the last two lines in the code:

1)Multiple markers at this line - Syntax error on token "STRING", VariableDeclaratorId expected after this token - Syntax error on token(s), misplaced construct(s)

2)Syntax error on token "close", Identifier expected after this token

import jep.Jep;

public class jeptest {
//private static final String SCRIPT_PATH = null;
private ClassLoader cl;
private static String  STRING="C:\\Python26\\test_java.py";
Jep jep = new Jep(false,STRING,cl);
jep.runScript(STRING);
jep.close();
}

I am using eclipse and have included jep.jar in the reference libraries.As I am not quite familiar with java I donno if i am missing something trivial here.

Please check the code and help me with this....Thanks in advance!!

pythonisgr8