我从这个项目https://github.com/timmolter/XChange下载了 jar 文件,现在我正在尝试在 Eclipse 中运行一个示例程序。
运行前没有指示错误,但是在尝试运行它时,我收到以下错误消息。
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());
}
}
根据我的阅读,这可能是类路径中的问题,但不确定该怎么做。任何帮助,将不胜感激。