Enabling Spring With Plugins
Writing a code to integrate MQTT functionality in my Spring application development made me think, am I not doing this over and over again. Having been involved in different IoT applications and numerous other domains, MQTT became an essential part of almost all the applications that I prepared.
This is just one example of such a case, where we tend to write or maybe sometimes copy the same code again and again from one application to another. Thinking about how many seconds would have I played TT more, if I would have had something for the rescue.
On the same lines, is the Java Enabler Toolkit, that I thought could be a potential solution in the open source community.
What is the Java Enabler Toolkit??
Coding for hours the same code again, we plugged out the essentials and made them mere configurable stuff for others to use. Java Enabler Toolkit comprises of different components that can be used separately over choice. The entire toolkit is made out of a main Maven Parent, which further contains the different child components. The structure of the toolkit is as follows:
Sample Component – MQTT
Let’s take the example of the pain that I have been going through, MQTT.
The source code for the toolkit is available for use at the following location:
https://github.com/ankitarora12/TTNDJavaToolkit
Download the source code for the project.
The structure of the MQTT component looks as follows:
To build the entire toolkit run “mvn clean install” on the folder: TTNDJavaToolkit/toolkit-parent/
The jars would be built and be available for use.
To use MQTT jar in your project follow the steps:
- Create a directory “repo” under your custom project, where your pom file is located.
- Hook onto the folder <customProject>/repo/ (cd <customProject>/repo)
- Run the following commands:
- mvn install:install-file -Dfile=<baseDir>/TTNDJavaToolKit/toolkit-parent/pom.xml -DgroupId=com.ttnd.toolkit -DartifactId=toolkit-parent -Dversion=0.0.1-SNAPSHOT -Dpackaging=pom -DlocalRepositoryPath=.
- mvn install:install-file -Dfile=<baseDir>/TTNDJavaToolkit/toolkit-parent/toolkit-mqtt/target/toolkit-mqtt-0.1-jar-with-dependencies.jar -DgroupId=com.ttnd.toolkit -DartifactId=toolkit-mqtt -Dversion=0.1 -Dpackaging=jar -DlocalRepositoryPath=.
- Running the above commands prepares your local repository with the mqtt jar.
- Add the following lines to your pom file:
- Add the following lines under the <repositories> tag:
<repository>
<id>repo</id>
<url>file://${project.basedir}/repo</url>
</repository> - Then add the following lines under <dependencies> tag:
<dependency>
<groupId>com.ttnd.toolkit</groupId>
<artifactId>toolkit-mqtt </artifactId>
<version>0.1</version>
</dependency>
- Add the following lines under the <repositories> tag:
- Doing this adds the jar to your project.
Njoy!!!
Informative article. This will surely help in rapid development.