我想通过在我的Java应用程序中嵌入Jython来加载Python类。通过Jython加载Python类
我到目前为止的代码是
String pythonRoot = Main.class.getResource("/python").getPath(); PySystemState state = new PySystemState(); PyObject importer = state.getBuiltins().__getitem__(Py.newString("__import__")); PyObject sysModule = importer.__call__(Py.newString("sys")); final PyString pythonPath = Py.newString(pythonRoot); PyList path = (PyList) sysModule.__getattr__("path"); path.add(pythonPath); PyModule module = (PyModule) importer.__call__(Py.newString("building.blah.again.blah2.Test")); PyObject klass = module.__getattr__(Py.newString("Address")); AddressInterface ai = (AddressInterface) klass.__call__().__tojava__(AddressInterface.class);
我试图访问的类可以在
/python/building/blah/again/blah2/Test.py
被发现和类的名称是
Address
但是,这给了我例外
Exception in thread "main" ImportError: No module named blah2
如果我把上面的目录中的一些文件,像这样
/python/building/blah/again/Test.py
这让我异常
Exception in thread "main" ImportError: No module named again
就好像他正在积极拒绝承认目录包含的文件。这里可能是什么问题,我该如何着手解决这个问题?