2010-08-07 6 views
0

간단한 Python 스크립트를 호출하기 위해 Jetty 서버 (모두 Maven을 통해)에서 Jython을 사용하려고합니다.내장 된 Jetty에서 Jython을 사용하여 "logging"모듈을 가져올 수 없음 -> ImportError : 특정 모듈을 찾을 수 없음

'로깅'과 같은 표준 라이브러리를 사용하지 않는 한 내 스크립트는 정상적으로 작동합니다. 표준 라이브러리 중 하나를 가져 오려고 할 때마다 "ImportError"예외가 발생합니다.

내가 얻을 예외입니다 :

File "<string>", line 1, in <module> 
    File "c:\home\work\sample\content\helloworld\helloworld.py", line 10, in <module> 
    import logging 
    File "c:\home\work\sample\content\Lib\logging\__init__.py", line 29, in <module> 
    import sys, os, types, time, string, cStringIO, traceback 
    File "c:\home\work\sample\content\Lib\os.py", line 119, in <module> 
    raise ImportError, 'no os specific module found' 
ImportError: no os specific module found 

    at org.python.core.PyException.fillInStackTrace(PyException.java:70) 
    at java.lang.Throwable.<init>(Throwable.java:181) 
    at java.lang.Exception.<init>(Exception.java:29) 
    at java.lang.RuntimeException.<init>(RuntimeException.java:32) 
    at org.python.core.PyException.<init>(PyException.java:46) 
    at org.python.core.PyException.doRaise(PyException.java:200) 
    at org.python.core.Py.makeException(Py.java:1159) 
    at org.python.core.Py.makeException(Py.java:1163) 
    at os$py.f$0(c:\home\work\sample\content\Lib\os.py:692) 
    at os$py.call_function(c:\home\work\sample\content\Lib\os.py) 
    at org.python.core.PyTableCode.call(PyTableCode.java:165) 
    at org.python.core.PyCode.call(PyCode.java:18) 
    at org.python.core.imp.createFromCode(imp.java:325) 
    at org.python.core.imp.createFromPyClass(imp.java:144) 
    at org.python.core.imp.loadFromSource(imp.java:504) 
    at org.python.core.imp.find_module(imp.java:410) 
    at org.python.core.imp.import_next(imp.java:620) 
    at org.python.core.imp.import_first(imp.java:650) 
    at org.python.core.imp.import_name(imp.java:741) 
    at org.python.core.imp.importName(imp.java:791) 
    at org.python.core.ImportFunction.__call__(__builtin__.java:1236) 
    at org.python.core.PyObject.__call__(PyObject.java:367) 
    at org.python.core.__builtin__.__import__(__builtin__.java:1207) 
    at org.python.core.__builtin__.__import__(__builtin__.java:1190) 
    at org.python.core.imp.importOne(imp.java:802) 
    at logging$py.f$0(c:\home\work\sample\content\Lib\logging\__init__.py:1372) 
    at logging$py.call_function(c:\home\work\sample\content\Lib\logging\__init__.py) 
    at org.python.core.PyTableCode.call(PyTableCode.java:165) 
    at org.python.core.PyCode.call(PyCode.java:18) 
    at org.python.core.imp.createFromCode(imp.java:325) 
    at org.python.core.imp.createFromPyClass(imp.java:144) 
    at org.python.core.imp.loadFromSource(imp.java:504) 
    at org.python.core.imp.find_module(imp.java:410) 
    at org.python.core.imp.import_next(imp.java:620) 
    at org.python.core.imp.import_first(imp.java:650) 
    at org.python.core.imp.import_name(imp.java:741) 
    at org.python.core.imp.importName(imp.java:791) 
    at org.python.core.ImportFunction.__call__(__builtin__.java:1236) 
    at org.python.core.PyObject.__call__(PyObject.java:367) 
    at org.python.core.__builtin__.__import__(__builtin__.java:1207) 
    at org.python.core.__builtin__.__import__(__builtin__.java:1190) 
    at org.python.core.imp.importOne(imp.java:802) 
    at helloworld.helloworld$py.f$0(c:\home\work\sample\content\helloworld\helloworld.py:19) 
    at helloworld.helloworld$py.call_function(c:\home\work\sample\content\helloworld\helloworld.py) 
    at org.python.core.PyTableCode.call(PyTableCode.java:165) 
    at org.python.core.PyCode.call(PyCode.java:18) 
    at org.python.core.imp.createFromCode(imp.java:325) 
    at org.python.core.imp.createFromPyClass(imp.java:144) 
    at org.python.core.imp.loadFromSource(imp.java:504) 
    at org.python.core.imp.find_module(imp.java:410) 
    at org.python.core.PyModule.impAttr(PyModule.java:109) 
    at org.python.core.imp.import_next(imp.java:622) 
    at org.python.core.imp.import_name(imp.java:761) 
    at org.python.core.imp.importName(imp.java:791) 
    at org.python.core.ImportFunction.__call__(__builtin__.java:1236) 
    at org.python.core.PyObject.__call__(PyObject.java:367) 
    at org.python.core.__builtin__.__import__(__builtin__.java:1207) 
    at org.python.core.imp.importFromAs(imp.java:869) 
    at org.python.core.imp.importFrom(imp.java:845) 
    at org.python.pycode._pyx1.f$0(<string>:1) 
    at org.python.pycode._pyx1.call_function(<string>) 
    at org.python.core.PyTableCode.call(PyTableCode.java:165) 
    at org.python.core.PyCode.call(PyCode.java:18) 
    at org.python.core.Py.runCode(Py.java:1197) 
    at org.python.core.Py.exec(Py.java:1241) 
    at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:138) 

내 스크립트는 다음과 같습니다

from java.util import Random 
from java.util import Date 

import sys 

print(sys.path) 
print(sys.builtin_module_names) 

import logging 

logging.basicConfig(level=logging.WARNING) 
logger1 = logging.getLogger('aaa') 
logger1.warning('************* This message comes from one module') 

def say_hello(): 
     return 'hello world1' 

나는 지금까지 다음을 시도했지만 아무 일 없다 :

  • 내 클래스 경로에 'Lib'디렉토리의 압축 포함
  • 인터프리터를 설정할 때 하드 코딩 'Lib'경로.

대화 형 자이 썬 셸에서 직접 처리하면 스크립트가 제대로 작동하고 로깅 메시지가 나타납니다.

감사합니다.

는 KJQ 나는 내 자신의 질문에 대한 답을 발견했습니다 지금 생각

답변

2

... 기본적으로

, 난 내 경로 함께 할 수있는 뭔가를 알고 있었다하지만 어떻게 알아낼 수 없었다 그들.

필자는 설치 프로그램을 통해 자이 썬 항아리의 "독립 실행 형"버전을 만들고 그 파일을/Libs 디렉토리에 포함하고 사용했다.