The Jython Class files are in the jar file, and the search path for Jython doesn't care if they are in jar file or not. All we need is to locate where the Jython classes are, and let Jython know about it.
From the hint of this post(How to get the path of a running JAR file?), one can find the path where the jar file is located. The class files can be found in the location + "py" directory.
For development purposes, the Jython source code in the source directory should also be specified ("src/py").
String runningDir = Simulate.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String jarPointer = "py";
String joinedPath = new File(runningDir, jarPointer).toString();
String pythonSrcPath = "/Users/smcho/code/PycharmProjects/aggregator/src";
JythonObjectFactory.setupPath(new String[]{joinedPath, "src/py"});
After this modification, the Jython could find the classes correctly.
This is the setupPath
method for setting up Jython search path.
public static void setupPath(String[] paths)
{
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("import sys;");
for (int i = 0; i < paths.length; i++) {
interpreter.exec(String.format("sys.path.append(\"%s\")", paths[i]));
}
}