Prepare your development environment (Java)
November 14, 2017 · View on GitHub
This document describes how to prepare your development environment to use the Azure IoT Edge for Java module development.
## Install Java JDK SE To use Azure IoT Edge and run the samples you will need a **32-bit** installation of a **JDK** (it is insufficient to only have the JRE installed).Windows
For downloads and installation instructions go here: http://www.oracle.com/technetwork/java/javase/downloads/index.html
Set up environment variables
- Please make sure that the
JAVA_HOMEenvironment variable includes the full path to thejdk1.x.xdirectory. (Example: JAVA_HOME=C:\Program Files\Java\jdk1.8.0_92) - Please make sure that the
PATHenvironment variable includes the full path to thejdk1.x.x\jre\bindirectory. (Example: %JAVA_HOME%\bin) - Please make sure that the
PATHenvironment variable includes the full path to thejdk1.x.x\jre\bin\serverdirectory. (Example: %JAVA_HOME%\jre\bin\server)
You can test whether your PATH variable is set correctly by restarting your console and running java -version.
Linux
Depending on your Linux distribution, you can install the JDK using apt-get, alternatively, you may visit the link above to find the download and instructions for Linux x86.
Set up environment variables
-
Please make sure that the
PATHenvironment variable includes the full path to the bin folder containing java as well as the server directory containing the jvm.which java echo $PATHEnsure that the bin directory shown by the
which javacommand matches one of the directories shown in your PATH. If it is not:export PATH=/path/to/java/bin:$PATH export PATH=/path/to/java/jre/lib/amd64/server:$PATH -
Please make sure that the
JAVA_HOMEenvironment variable includes the full path to the jdk.update-alternatives --config javaTake note of the jdk location.
update-alternativeswill 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
Windows
For downloads and installation instructions go here: https://maven.apache.org/download.cgi
Set up environment variables
- Please make sure that the
PATHenvironment variable includes the full path to theapache-maven-3.x.x\bindirectory. (Example: F:\Setups\apache-maven-3.3.3\bin). Theapache-maven-3.x.xdirectory 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.
Linux
On Linux, Maven 3 can be installed as follows:
sudo apt-get update
sudo apt-get install maven
Set up environment variables
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
```
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 Java module binding for Azure IoT Edge. 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/iot-edge.git
cd iot-edge/bindings/java/gateway-java-binding
mvn clean install
The compiled JAR file with all dependencies bundled in can then be found at:
{Azure IoT Edge root}/bindings/java/gateway-java-binding/target/gateway-java-binding-{version}.jar
When you're ready to build your own module in Java, include this JAR file in your project to get the interfaces and classes that you need.
This repository contains a sample gateway that includes modules written in Java that illustrate how to write modules in Java and use Azure IoT Edge. For more information, see the readme.