流.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):
Exception in thread "main" java.lang.NoClassDefFoundError: org/reactivestreams/Publisher
....
Caused by: java.lang.ClassNotFoundException: org.reactivestreams.Publisher
我正在关注 tutorial在第六页,除了我决定使用 gradle 而不是 maven
编辑
可能是 gradle 和 Intellij IDEA 的一些问题
以下解决了问题: 设置.gradle:
rootProject.name = 'JavaRx'
include "buildSrc"
最佳答案
异常意味着 org.reactivestreams.Publisher 类在运行时不可用。所以它在类路径中丢失了。您可以通过在 gradle 中添加依赖引用来添加到类路径中。
根据您使用的版本,它应该如下所示:
dependencies {
compile group: 'org.reactivestreams', name: 'reactive-streams', version: '1.0.0'
...<the other depandancies>...
}
关于java - 为什么我收到 NoClassDefFoundError : org/reactivestreams/Publisher,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43231477/