我的主要模块被装上外壳,然后是一米,试图进口一个.式模块,该模块位于与我的Runner java级一样的主要.器模块。
但i m还未成功。 我的设想;
My package structure:
/
/test/
/test/Runner.java
/test/myfirst.py
/test/mySecond.py
/test/__init__.py
In Runner.java:
InputStream mPython = getClass().getClassLoader().getResourceAsStream("test/myFirst.py" );
PythonInterpreter mInterp = new PythonInterpreter();
mInterp.execfile( mPython );
In myfirst.py
import sys
print sys.path
import mySecond
mySecond.hello()
In mySecond.py
def hello():
print "hi"
我尝试了各种事情,用测试等来抵消,没有成功。
Below the output when running debug from my netbeans7 java project. Thought to show the sys.path as well. Maybe it helps getting a solution
debug:
[ D:\....\ext\Lib , __classpath__ , __pyclasspath__/ ]
Exception in thread "main" Traceback (most recent call last):
File "<iostream>", line 3, in <module>
ImportError: No module named mySecond
Java Result: 1
BUILD SUCCESSFUL (total time: 4 seconds)
I assume it s to do with the .py files not being on disk, but to be loaded from my java classpath? Any ideas are welcome
<><>UPDATE:
展望是一个比较一般性的问题。 进口os甚至失败。 我的道路环境是错误的。 标明校准目录似乎可以确定;
PySystemState mPyState = new PySystemState();
mPyState.path.insert(0,new PyString("C:\jython2.5.1\Lib"));
PythonInterpreter mInterp = new PythonInterpreter( null, mPyState );
我认为,这导致了问题;
Found a good source on how importing works for Jython here