Why am I getting NoClassDefFoundError: org / reactivestreams / Publisher
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'
}
An exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/reactivestreams/Publisher
....
Caused by: java.lang.ClassNotFoundException: org.reactivestreams.Publisher
I am following the tutorial on page 6, except that I decided to use gradle instead of maven
Edit
Possibly a problem with gradle and Intellij IDEA
After fixing the problem: settings.gradle:
rootProject.name = 'JavaRx'
include "buildSrc"
+4
source to share
2 answers
The exception means that the org.reactivestreams.Publisher class is not available at runtime. Therefore, it is missing from the classpath. You can add to classpath by adding dependency link in gradle.
Depending on the version used, it should look like this:
dependencies {
compile group: 'org.reactivestreams', name: 'reactive-streams', version: '1.0.0'
...<the other depandancies>...
}
+6
source to share
I got this exception using org.springframework.test.web.reactive.server.WebTestClient, so it's easy to fix it with spring-boot just by adding this dependency to your pom.xml (for maven projects):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
0
source to share