2012-08-01 66 views
0

我在一個jar中的應用程序依賴於不同罐子中的一些庫。Jython Jar依賴項導入失敗

這是我的問題: 當我只導入我的主應用程序文件時,jython似乎正確加載類,但通過NoClassDefError(一個支持庫jar中表示的一個)缺少類。

但是,如果我現在jar添加到classpath中的Jython再也找不到原來的進口,並且抱怨:ImportError: No module named edu

我的代碼:

import sys 

def setClassPath(): 
    libDir = "/Users/gestalt/Documents/msmexplorer_git/msmexplorer/MSMExplorer/" 
    classPaths = [ 
      "dist/MSMExplorer.jar" 
      "dist/lib/prefuse.jar" #the missing class is here, but this line causes package edu to go missing 
    ] 
    for classPath in classPaths: 
      sys.path.append(libDir+classPath) 

def runJavaClass(): 
    from edu.stanford.folding.msmexplorer import MSMExplorer 
    me = MSMExplorer() 

def main(): 
    setClassPath() 
    runJavaClass() 

if __name__ == "__main__": 
    main() 

謝謝!

+0

這是否需要Java標記? – 2012-08-01 06:44:31

+0

@Duncan由於其中一些涉及jar-wrangling和java classpath問題,我認爲這不是不合理 – bcr 2012-08-01 06:46:24

回答

0

聽起來很愚蠢,這是某種特殊的語法錯誤。瓶子規格之間需要逗號:

"dist/MSMExplorer.jar", 
"dist/lib/prefuse.jar" 
+0

是的,Python(以及Jython)隱式地將字符串連接在一起成爲一個字符串,如果它們之間只有空格。大多數時候這是非常方便的:) – 2012-08-01 16:24:41