From 8af6bb0716121e5446e855d0c1e141d5bfbb325b Mon Sep 17 00:00:00 2001 From: Mandeep Dhami <mandeep.dhami@bigswitch.com> Date: Thu, 19 Jan 2012 19:35:03 -0800 Subject: [PATCH] Changed jarpath to work in eclipse and dev env as well --- .../floodlightcontroller/jython/Server.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/floodlightcontroller/jython/Server.java b/src/main/java/net/floodlightcontroller/jython/Server.java index 8f17b9964..cd330fa27 100644 --- a/src/main/java/net/floodlightcontroller/jython/Server.java +++ b/src/main/java/net/floodlightcontroller/jython/Server.java @@ -1,26 +1,50 @@ package net.floodlightcontroller.jython; +import java.net.URL; import java.util.Map; import org.python.util.PythonInterpreter; +/** + * This class starts a thread that runs a jython interpreter that + * can be used for debug (or even development). + * + * @author mandeepdhami + * + */ public class Server extends Thread { int port; Map<String, Object> locals; + /** + * @param port_ Port to use for jython server + * @param locals_ Locals to add to the interpreters top level name space + */ public Server(int port_, Map<String, Object> locals_) { this.port = port_ ; this.locals = locals_; } + /** + * The main thread for this class invoked by Thread.run() + * + * @see java.lang.Thread#run() + */ public void run() { PythonInterpreter p = new PythonInterpreter(); for (String name : this.locals.keySet()) { p.set(name, this.locals.get(name)); } - String jarPath = Server.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + URL jarUrl = Server.class.getProtectionDomain().getCodeSource().getLocation(); + String jarPath = jarUrl.getPath(); + if (jarUrl.getProtocol().equals("file")) { + // If URL is of type file, assume that we are in dev env and set path to python dir. + // else use the jar file as is + jarPath = jarPath + "../../src/main/python/"; + } + p.exec("import sys"); p.exec("sys.path.append('" + jarPath + "')"); p.exec("from debugserver import run_server"); -- GitLab