2012-05-30 76 views
2

我正在使用Apache Commons CLI 1.2來解析Java中的命令行參數。試圖運行我的java類時遇到了NoClassDefFoundError,但通過修復類路徑來解決它。Java:使用Apache Commons CLI 1.2的NoClassDefFoundError

現在我有同樣的異常,但在關於實際commons-cli類爲如下所示:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cl i/CommandLineParser Caused by: 
    java.lang.ClassNotFoundException: org.apache.commons.cli.CommandLineP arser 
      at java.net.URLClassLoader$1.run(Unknown Source) 
      at java.security.AccessController.doPrivileged(Native Method) 
      at java.net.URLClassLoader.findClass(Unknown Source) 
      at java.lang.ClassLoader.loadClass(Unknown Source) 
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
      at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: com.amirsys.score.api.script.CMDContentPusher. 

我能想到的唯一的事情就是設置類路徑公地CLI罐子但那沒用。我一直無法找到解決導入類的NoClassDefFoundError的解決方案。我認爲這些被編譯到.class文件中?

+0

這可能是有用的:http://stackoverflow.com/questions/1457863/what-is-the-difference-between-noclassdeffounderror -and-classnotfoundexception –

+0

你究竟如何運行應用程序?看起來像commons-cli不在類路徑中... – centic

+0

我試圖從Windows命令行運行它。那麼我是否需要在最初的參數中添加公共cli的類路徑?我有一種可怕的感覺,我會在類路徑配置的紗球中迷路...有沒有更簡單的方法? –

回答

1

Commons CLI在運行時不在類路徑中。如果您很難獲得類路徑,您可以嘗試將應用程序打包爲包含所有依賴項的單個大型jar文件,包括Commons CLI。有很多工具可以實現(jarjar,onejar,Maven shade插件...)

相關問題