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:
- Reference diozero as the Maven parent. Use diozero-example as a reference.
- Add diozero as a dependency in your application’s Maven
pom.xml. Seethe diozero Java Lego Car project as an example.
If you need to use a diozero snapshot build, make sure you enable Maven snapshot repositories by adding the following XML snippet to your application’s
<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>
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.3 -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
<profiles> <profile> <id>snapshot-profile</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>archetype</id> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> </repository> </repositories> </profile> </profiles>
To package your application so you can copy it to your device again there are a number of options.
- Export your application as a JAR file and include all run-time dependencies via the classpath. Simply run
mvn packageto 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.3.jar:yourapp.jar <<your-main-class>>.
- 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.
- Use the Maven shade plugin to create a runnable JAR file that includes all dependencies. Run
mvn packageto create the runnable JAR file.