Skip to content
Snippets Groups Projects
Commit 8af6bb07 authored by Mandeep Dhami's avatar Mandeep Dhami
Browse files

Changed jarpath to work in eclipse and dev env as well

parent 8f9fea7a
No related branches found
No related tags found
No related merge requests found
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");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment