Creating Your Own diozero Application

To create your own application that uses diozero I recommend that you use Apache Maven to manage dependencies. Gradle also provides similar functionality however I haven't had a chance to look into using it.

There are 2 main approaches for incorporating diozero into your project using Maven

  1. Reference diozero as the Maven parent. Use diozero-example as a reference.

  2. Add diozero as a dependency in your application's Maven pom.xml. See my Java Lego Car project as an example. Note make sure you enable Maven snapshot repositories if you want to use a diozero snapshot build. xml <repositories> <repository> <id>oss-snapshots-repo</id> <name>Sonatype OSS Maven Repository</name> <url>https://oss.sonatype.org/content/groups/public</url> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories>

If you want to manage the dependencies yourself, download and exract a diozero distribution ZIP file from Google Drive and add tinylog-1.2.jar and diozero-core.jar to your project's classpath.

Step-by-step Instructions

These instructions assume you are using Eclipse, Maven and are using diozero as the parent project.

  1. Create a new Java Project

    New Java Project

  2. Copy the example pom.xml into your project

  3. Change the groupId, artifactId and name attributes in your pom.xml

    Example pom.xml

  4. Right click on your Java project and chose Configure / Convert to Maven Project

  5. Check that the Maven dependencies have been correctly imported by exanding Maven Dependencies in the Package Explorer side bar

    Maven Dependencies

  6. Develop your application

  7. Compile, package and distribute your application

    Compile and Package

Deploy Your Application to Your Device

To package your application so you can copy it to your device again there are a number of options.

  1. Export your application as a JAR file and include all run-time dependencies via the classpath. Simply run mvn package to create the JAR file for your application. Note this will not generate a runnable JAR hence you will need to run your application as java -cp tinylog-1.2.jar:diozero-core.jar:yourapp.jar <<your-main-class>>.

  2. You can use Eclipse to create an runnable JAR file that includes all dependencies and sets. Note a runnable JAR file is one that can be run from the command line using java -jar yourapp.jar. First make sure you have created a run configuration so Eclipse knows the main class for your application; right click on you main class and choose Run As / Java Application. Then right click on your project in the Eclipse package Explorer side bar and choose Export / Java / Runnable JAR file. Make sure you select the correct Launch configuration for your application.

    Export Runnable JAR

  3. Use the Maven shade plugin to create a runnable JAR file that includes all dependencies. Run mvn package to create the runnable JAR file. See my webapp project for an example.