Why I am getting NoClassDefFoundError: org/reactivestreams/Publisher

一笑奈何 提交于 2019-12-12 11:23:48

问题


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:

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

I am following the tutorial at page six, except I decided to use gradle instead of maven

Edit

Probably some issue with gradle and Intellij IDEA

Following fixed the issue: settings.gradle:

rootProject.name = 'JavaRx'

include "buildSrc"

回答1:


The exception means that the class org.reactivestreams.Publisher is not available at runtime. So it is missing in the classpath. You can add to the classpath, by adding the dependency-reference in gradle.

Depending on your used version it should look like:

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



回答2:


I got this exception using org.springframework.test.web.reactive.server.WebTestClient so it's easy to fix with spring-boot, just adding this dependency to your pom.xml (for maven projects):

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>


来源:https://stackoverflow.com/questions/43231477/why-i-am-getting-noclassdeffounderror-org-reactivestreams-publisher

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!