Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I am getting NoClassDefFoundError: org/reactivestreams/Publisher

Tags:

java

reactivex

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"
like image 807
sakhunzai Avatar asked Apr 05 '17 12:04

sakhunzai


2 Answers

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>...
}
like image 124
nikmaster Avatar answered Oct 09 '22 02:10

nikmaster


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>
like image 32
Alan Teals Avatar answered Oct 09 '22 02:10

Alan Teals