2017-04-05 92 views
2

Stream.java为什么我得到NoClassDefFoundError的:组织/ reactivestreams /发行商

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" 
+0

我想你应该添加依赖于org.reactivestreams.reactive流 –

回答

4

例外意味着该类org.reactivestreams.Publisher在运行时不可用。所以它在类路径中丢失了。您可以通过在gradle中添加依赖关系引用来添加到类路径中。

根据所使用的版本,它应该是这样的:

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

但gradle这个拒绝进口的依赖,什么也不做 – sakhunzai

+0

哦,对不起,就我现在看到的,你可以参考maven central。所以https://search.maven.org的例子应该会更好。 (在我使用“我的”已知存储库作为参考之前)。希望这有效。如果没有,你应该检查你真正使用过的仓库(看看你的仓库是如何定义这个虚假的)。 因此,请尝试:编译'org.reactivestreams:reactive-streams:1.0.0.final' – nikmaster

+0

问题是为什么我应该关心依赖关系,是不是Gradle的任务(取得关联的依赖关系)? – sakhunzai