Stream.java
import io.reactivex.*;
public class Stream {
public static void main(String args[])
{
Observable.just("Howdy!").subscribe(System.out::println);
}
}
构建.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 https://www.infoq.com/minibooks/emag-reactive-programming-java在第六页,除了我决定使用 gradle 而不是 Maven
Edit
可能是 gradle 和 Intellij IDEA 的一些问题
以下修复了该问题:
设置.gradle:
rootProject.name = 'JavaRx'
include "buildSrc"
异常意味着该类org.reactivestreams.Publisher在运行时不可用。所以它在类路径中丢失了。您可以通过在 gradle.xml 中添加依赖项引用来添加到类路径中。
根据您使用的版本,它应该如下所示:
dependencies {
compile group: 'org.reactivestreams', name: 'reactive-streams', version: '1.0.0'
...<the other depandancies>...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)