编程语言
首页 > 编程语言> > java – 为什么我得到NoClassDefFoundError:org / reactivestreams / Publisher

java – 为什么我得到NoClassDefFoundError:org / reactivestreams / Publisher

作者:互联网

Stream.java

import io.reactivex.*;


public class Stream {

    public static void main(String args[])
    {

      Observable.just("Howdy!").subscribe(System.out::println);

    }
}

的build.gradle:

group 'com.sakhunzai'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
    mavenCentral()
}

dependencies {
    compile 'io.reactivex.rxjava2:rxjava:2.0.5'
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

例外:

Exception in thread "main" java.lang.NoClassDefFoundError: org/reactivestreams/Publisher
....
Caused by: java.lang.ClassNotFoundException: org.reactivestreams.Publisher

我在第六页跟随tutorial,除了我决定使用gradle而不是maven

编辑

可能是gradle和Intellij IDEA的一些问题

以下修正了问题:
settings.gradle:

rootProject.name = 'JavaRx'

include "buildSrc"

解决方法:

该异常意味着类org.reactivestreams.Publisher在运行时不可用.所以它在类路径中丢失了.您可以通过在gradle中添加dependency-reference来添加到类路径中.

根据您使用的版本,它应如下所示:

dependencies {
    compile group: 'org.reactivestreams', name: 'reactive-streams', version: '1.0.0'
    ...<the other depandancies>...
}

标签:java,reactivex
来源: https://codeday.me/bug/20190611/1217726.html