Skip to content

Latest commit

 

History

History
91 lines (62 loc) · 3.17 KB

java-run-sample.md

File metadata and controls

91 lines (62 loc) · 3.17 KB
platform device language
debian, fedora, Linux, opensuse, raspbian, Ubuntu, windows, yocto
any
java

Run a simple Java sample on device


Table of Contents

Introduction

About this document

This document describes how to build and run the Java sample application. This multi-step process includes:

  • Configuring Azure IoT Hub
  • Registering your IoT device
  • Build and deploy Azure IoT SDK on device

Step 1: Prerequisites

You should have the following items ready before beginning the process:

Step 2: Prepare your Device

Step 3: Build and Run the sample

If you have successfully prepared your development environment the IoT device SDK and all samples should be built and ready to use.

  1. Start a new instance of the [Device Explorer][device-explorer], select or create a new device, obtain and note the connection string for the device, and begin moitoring under the Data tab.

  2. Navigate to the folder containing the executable JAR file for the sample that you wish to run and run the samples as follows:

    The executable JAR file for sending event can be found at:

    {IoT device SDK root}/java/device/samples/send-event/target/send-event-{version}-with-deps.jar
    

    Navigate to the directory with the event sample. Run the sample using the following command:

    java -jar ./send-event-{version}-with-deps.jar "{connection string}" "{number of requests to send}" "{https or amqps}"
    

    The executable JAR file for receiving messages can be found at:

    {IoT device SDK root}/java/device/samples/handle-messages/target/handle-messages-{version}-with-deps.jar
    

    Navigate to the directory with the messages sample. Run the sample using the following command:

    java -jar ./handle-messages-{version}-with-deps.jar "{connection string}" "{https or amqps}"
    

    Note that the double quotes around each argument are required, but the braces '{' and '}' should be removed.

Next Steps

To learn how to create a Java application that communicates with an IoT hub from scratch, see Get started with Azure IoT Hub for Java.

Documentation

The documentation can be found here.