我從該項目下載了這個jar文件https://github.com/timmolter/XChange,我現在試圖獲得一個在Eclipse中運行的示例程序。試圖將JAR文件添加到項目中,但獲取NoClassDefFoundError
沒有錯誤在運行前顯示,但試圖運行時,我收到以下錯誤消息。
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.xeiam.xchange.ExchangeFactory.<init>(ExchangeFactory.java:41)
at com.xeiam.xchange.ExchangeFactory.<clinit>(ExchangeFactory.java:39)
at com.xeiam.xchange.rhbotha.bot.Main.main(Main.java:18)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
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)
... 3 more
這是我的代碼。
package com.xeiam.xchange.rhbotha.bot;
import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.ExchangeFactory;
import com.xeiam.xchange.currency.Currencies;
import com.xeiam.xchange.dto.marketdata.Ticker;
import com.xeiam.xchange.mtgox.v1.MtGoxExchange;
import com.xeiam.xchange.service.marketdata.polling.PollingMarketDataService;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// Use the factory to get the version 1 MtGox exchange API using default settings
Exchange mtGoxExchange = ExchangeFactory.INSTANCE.createExchange(MtGoxExchange.class.getName());
// Interested in the public polling market data feed (no authentication)
PollingMarketDataService marketDataService = mtGoxExchange.getPollingMarketDataService();
// Get the latest ticker data showing BTC to USD
Ticker ticker = marketDataService.getTicker(Currencies.BTC, Currencies.USD);
System.out.println(ticker.toString());
// Get the latest ticker data showing BTC to EUR
ticker = marketDataService.getTicker(Currencies.BTC, Currencies.EUR);
System.out.println(ticker.toString());
// Get the latest ticker data showing BTC to GBP
ticker = marketDataService.getTicker(Currencies.BTC, Currencies.GBP);
System.out.println(ticker.toString());
}
}
從我讀過的內容可能是類路徑中的問題,但不知道該怎麼做。任何幫助,將不勝感激。
該項目有一個pom.xml。使用maven來管理依賴關係或使用項目wiki上的[依賴信息](https://github.com/timmolter/XChange)來管理它。我會推薦前者。 –
如何在Eclipse中使用pom.xml文件? – Rynardt
使用[m2eclipse](http://www.sonatype.org/m2eclipse/)插件。 –