Skip to content

Instantly share code, notes, and snippets.

@vkravets
Created October 26, 2012 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vkravets/3959365 to your computer and use it in GitHub Desktop.
Save vkravets/3959365 to your computer and use it in GitHub Desktop.
Running jython via Nailgun server
public class JythonNailgun {
private static PythonIterpreter interpreter = null;
public static void nailMain (NGContext context) {
if (interpreter == null) {
interpreter = new PythonIterpreter();
} else {
Py.setSystemState(new PySystemState());
}
PySystemState systemState = interpreter.getSystemState();
systemState.setCurrentWorkingDir(context.getWorkingDirectory());
interpreter.setErr(context.err);
interpreter.setIn(context.in);
interpreter.setOut(context.out);
systemState.argv = new PyList(PyType.fromClass(String.class), Arrays.asList(context.getArgs()));
String pythonPath = System.getProperties().getProperty("python.path");
if (pythonPath != null) {
String[] tokes = pythonPath.split(context.getPathSeparator());
systemState.path = new PyList(PyType.fromClass(String.class), Arrays.asList(tokens))
}
interpreter.execfile(context.getArgs()[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment