public static PyJavaPackage add_package(String n) { return add_package(n, null); }
public static PythonInterpreter getPythonInterpreter() { if (interpreter == null) { interpreter = new PythonInterpreter(); PySystemState sys = Py.getSystemState(); sys.add_package("javax.management"); sys.add_package("javax.management.loading"); sys.add_package("javax.management.modelmbean"); sys.add_package("javax.management.monitor"); sys.add_package("javax.management.openmbean"); sys.add_package("javax.management.remote"); sys.add_package("javax.management.remote.rmi"); sys.add_package("javax.management.relation"); sys.add_package("javax.management.timer"); try { String script = loadStream(JythonRunner.class.getClassLoader().getResourceAsStream("mx4j/tools/jython/jmxUtils.py")); interpreter.exec(script); } catch (IOException e) { e.printStackTrace(); } } return interpreter; }
/** * PyServlet's initialization can be performed as a ServletContextListener or as a regular * servlet, and this is the shared init code. If both initializations are used in a single * context, the system state initialization code only runs once. */ protected static void init(Properties props, ServletContext context) { String rootPath = getRootPath(context); context.setAttribute(INIT_ATTR, true); Properties baseProps = PySystemState.getBaseProperties(); // Context parameters Enumeration<?> e = context.getInitParameterNames(); while (e.hasMoreElements()) { String name = (String)e.nextElement(); props.put(name, context.getInitParameter(name)); } if (props.getProperty("python.home") == null && baseProps.getProperty("python.home") == null) { props.put("python.home", rootPath + "WEB-INF" + File.separator + "lib"); } PySystemState.initialize(baseProps, props, new String[0]); PySystemState.add_package("javax.servlet"); PySystemState.add_package("javax.servlet.http"); PySystemState.add_package("javax.servlet.jsp"); PySystemState.add_package("javax.servlet.jsp.tagext"); PySystemState.add_classdir(rootPath + "WEB-INF" + File.separator + "classes"); PySystemState.add_extdir(rootPath + "WEB-INF" + File.separator + "lib", true); }