RxJava - Environment Setup


Advertisements

Local Environment Setup

RxJava is a library for Java, so the very first requirement is to have JDK installed in your machine.

System Requirement

JDK 1.5 or above.
Memory No minimum requirement.
Disk Space No minimum requirement.
Operating System No minimum requirement.

Step 1 - Verify Java Installation in Your Machine

First of all, open the console and execute a java command based on the operating system you are working on.

OS Task Command
Windows Open Command Console c:\> java -version
Linux Open Command Terminal $ java -version
Mac Open Terminal machine:< joseph$ java -version

Let's verify the output for all the operating systems −

OS Output
Windows

java version "1.8.0_101"

Java(TM) SE Runtime Environment (build 1.8.0_101)

Linux

java version "1.8.0_101"

Java(TM) SE Runtime Environment (build 1.8.0_101)

Mac

java version "1.8.0_101"

Java(TM) SE Runtime Environment (build 1.8.0_101)

If you do not have Java installed on your system, then download the Java Software Development Kit (SDK) from the following link https://www.oracle.com. We are assuming Java 1.8.0_101 as the installed version for this tutorial.

Step 2 - Set JAVA Environment

Set the JAVA_HOME environment variable to point to the base directory location where Java is installed on your machine. For example.

OS Output
Windows Set the environment variable JAVA_HOME to C:\Program Files\Java\jdk1.8.0_101
Linux export JAVA_HOME = /usr/local/java-current
Mac export JAVA_HOME = /Library/Java/Home

Append Java compiler location to the System Path.

OS Output
Windows Append the string C:\Program Files\Java\jdk1.8.0_101\bin at the end of the system variable, Path.
Linux export PATH = $PATH:$JAVA_HOME/bin/
Mac not required

Verify Java installation using the command java -version as explained above.

Step 3 - Download RxJava2 Archive

Download the latest version of RxJava jar file from RxJava @ MVNRepository and its dependency Reactive Streams @ MVNRepository . At the time of writing this tutorial, we have downloaded rxjava-2.2.4.jar, reactive-streams-1.0.2.jar and copied it into C:\>RxJava folder.

OS Archive name
Windows rxjava-2.2.4.jar, reactive-streams-1.0.2.jar
Linux rxjava-2.2.4.jar, reactive-streams-1.0.2.jar
Mac rxjava-2.2.4.jar, reactive-streams-1.0.2.jar

Step 4 - Set RxJava Environment

Set the RX_JAVA environment variable to point to the base directory location where RxJava jar is stored on your machine. Let’s assuming we've stored rxjava-2.2.4.jar and reactive-streams-1.0.2.jar in the RxJava folder.

Sr.No OS & Description
1

Windows

Set the environment variable RX_JAVA to C:\RxJava

2

Linux

export RX_JAVA = /usr/local/RxJava

3

Mac

export RX_JAVA = /Library/RxJava

Step 5 - Set CLASSPATH Variable

Set the CLASSPATH environment variable to point to the RxJava jar location.

Sr.No OS & Description
1

Windows

Set the environment variable CLASSPATH to %CLASSPATH%;%RX_JAVA%\rxjava-2.2.4.jar;%RX_JAVA%\reactive-streams-1.0.2.jar;.;

2

Linux

export CLASSPATH = $CLASSPATH:$RX_JAVA/rxjava-2.2.4.jar:reactive-streams-1.0.2.jar:.

3

Mac

export CLASSPATH = $CLASSPATH:$RX_JAVA/rxjava-2.2.4.jar:reactive-streams-1.0.2.jar:.

Step 6 - Test RxJava Setup

Create a class TestRx.java as shown below −

import io.reactivex.Flowable;
public class TestRx {
   public static void main(String[] args) {
      Flowable.just("Hello World!").subscribe(System.out::println);
   }
}

Step 7 - Verify the Result

Compile the classes using javac compiler as follows −

C:\RxJava>javac Tester.java

Verify the output.

Hello World!
Advertisements