Link Search Menu Expand Document

Creating Your Own 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. Seethe diozero Java Lego Car project as an example. Note make sure you enable Maven snapshot repositories if you want to use a diozero snapshot build. The following XML snippet can be added to your application’s pom.xml file:

		<name>Sonatype OSS Maven Repository</name>

If you want to manage the dependencies yourself, download and extract a diozero-distribution ZIP file from either Maven Central or mvnrepository.

As of diozero 1.0.0 you can also start a new diozero application using the Maven archetype:

mvn archetype:generate -DarchetypeGroupId=com.diozero -DarchetypeArtifactId=diozero-application -DarchetypeVersion=1.3.0 -DgroupId=com.mycompany -DartifactId=mydiozeroapp -Dversion=1.0-SNAPSHOT

To use a snapshot version of the archetype you will need to add this snippet to your Maven settings.xml file (in $HOME/.m2):


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-2.2.1.jar:diozero-core-1.3.0.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.