This document describes how to prepare your development environment to use the Microsoft Azure IoT service SDK for Java.
## Install Java JDK SE To use the SDK and run the samples you will need **Java SE 8**.For downloads and installation instructions go here: http://www.oracle.com/technetwork/java/javase/downloads/index.html
- Please make sure that the
PATH
environment variable includes the full path to thejdk1.8.x\bin
directory. (Example: C:\Program Files\Java\jdk1.8.0_60\bin) - Please make sure that the
JAVA_HOME
environment variable includes the full path to thejdk1.8.x
directory. (Example: JAVA_HOME=C:\Program Files\Java\jdk1.8.0_60)
You can test whether your PATH
variable is set correctly by restarting your console and running java -version
.
Note: If you are running a version of Ubuntu below 14.10, you must run the command shown below to add the repository that contains the openjdk-8-jdk package to Ubuntu's list of software sources before you attempt to use the apt-get command to install openjdk-8-jdk:
sudo add-apt-repository ppa:openjdk-r/ppa
On Linux, the Java OpenJDK 8 can be installed as follows:
sudo apt-get update
sudo apt-get install openjdk-8-jdk
-
Please make sure that the
PATH
environment variable includes the full path to the bin folder containing java.which java echo $PATH
Ensure that the bin directory shown by the
which java
command matches one of the directories shown in your $PATH variable. If it does not:export PATH=/path/to/java/bin:$PATH
-
Please make sure that the
JAVA_HOME
environment variable includes the full path to the jdk.update-alternatives --config java
Take note of the jdk location.
update-alternatives
will show something similar to /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java. The jdk directory would then be /usr/lib/jvm/java-8-openjdk-amd64/.export JAVA_HOME=/path/to/jdk
For downloads and installation instructions go here: https://maven.apache.org/download.cgi
- Please make sure that the
PATH
environment variable includes the full path to theapache-maven-3.x.x\bin
directory. (Example: F:\Setups\apache-maven-3.3.3\bin). Theapache-maven-3.x.x
directory is where Maven 3 is installed.
You can verify that the environment variables necessary to run Maven 3 have been set correctly by restarting your console and running mvn --version
.
On Linux, Maven 3 can be installed as follows:
sudo apt-get update
sudo apt-get install maven
Please verify the following:
Ensure the PATH
environment variable contains the full path to the bin folder containing Maven 3.
```
which mvn
echo $PATH
```
Ensure that the bin directory shown by the which mvn
command matches one of the directories shown in your $PATH variable.
If it does not:
export PATH=/path/to/mvn/bin:$PATH
You can verify that the environment variables necessary to run Maven 3 have been set correctly by running mvn --version
.
- There are two ways to get the .jar library for the Azure IoT service SDK. You may either download the source code and build on your machine, or include the project as a dependency in your project if your project is a Maven project. Both methods are described below.
Open a command prompt and use the following commands for the steps above:
git clone https://github.com/Azure/azure-iot-sdks.git
cd azure-iot-sdks/java/service
mvn install
The compiled JAR file with all dependencies bundled in can then be found at:
{IoT SDK root}/java/service/iothub-java-client/target/iothub-java-client-{version}-with-deps.jar
When you're ready to use the Java SDK in your own project, include this JAR file in your project to use the IoT service SDK.
### Get Azure IoT service SDK for Java from Maven (as a dependency) _This is the recommended method of including the Azure IoT Service SDK in your project, however this method will only work if your project is a Maven project_- Navigate to http://search.maven.org, search for com.microsoft.azure.iothub-java-client and take note of the latest version number of the service client (or the version number of whichever version of the sdk you desire to use).
In your main pom.xml file, add the Azure IoT Service SDK as a dependency using your desired version as follows:
<dependency>
<groupId>com.microsoft.azure.iothub-java-client</groupId>
<artifactId>iothub-java-service-client</artifactId>
<version>1.0.2</version>
<!--This is the current version number as of the writing of this document. Yours may be different.-->
</dependency>
This repository contains various sample applications that illustrate how to use the Microsoft Azure IoT service SDK for Java. For more information, see the readme.
To learn how to run a simple Getting started Java application that sends messages to an IoT hub, see Getting started - running a Java sample.