java - 尝试将 JAR 文件添加到项目中,但出现 NoClassDefFoundError

标签 java jar runtime-error noclassdeffounderror

我从这个项目下载了 jar 文件 https://github.com/timmolter/XChange我现在正在尝试让示例程序在 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());

    }

}

据我所知,这可能是类路径中的问题,但不确定该怎么做。任何帮助将不胜感激。

最佳答案

你缺少这个 jar(可能是其他的):org.slf4j.LoggerFactory

我的建议是使用 Maven 来管理您的依赖项(通过 pom),但如果不下载这个 jar 并将其与其他 jar 包含在一起(即在类路径中)

关于java - 尝试将 JAR 文件添加到项目中,但出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15971550/

相关文章:

java - JasperReport java.util.NoSuchElementException

java - 最好将项目 jar 文件 Mavenize 或将它们放在 WEB-INF/lib 中?

Java用不同的值替换捕获组

java - Spring Batch 作业依赖

java - 不同人的 jar 尺寸不同

c# - 事件支持 WP 8.1

c++ - 使用复制构造函数创建对象(三类简单规则)会产生运行时错误

html - 未定义的方法 `error_span' - Rails 项目

java - 如何使用 querydsl 动态添加 where 子句?

Java永远不能 "find or load"主类