Deploy Java application to Raspberry Pi

I Recently got very frustrated that it took too long to deploy a Java application to my Raspberry Pi and decided to dig into this topic. I found the plugin “gradle-ssh-plugin” and it looks promising.

Requirements

First of all I need to create a Spring Boot application which is only an example app for this. If you do not know how to do this, check out this tutorial.

Gradle is a build tool which I am using in pretty much all of my projects. It is quite easy to use and no more XML. 🙂
Look at the gradle documentation if you want to find out more about gradle.

The plugin i found “gradle-ssh-plugin” was quite easy to work with. I created a task to define the deploy step. You define the host, user and password together with the jar file location and Raspberry Pi folder path. The task will then deploy the jar file to the Raspberry Pi.
You can look at the code below to view my task or check out the github repo here.

remotes {
    webServer {
        host = 'raspberrypi.local'
        user = 'pi'
        password = 'raspberry'
    }
}

task deploy {
    doLast {
        ssh.run {
            session(remotes.webServer) {
                put from: "${project.projectDir}/build/libs/hello-world-springboot-0.1.0.jar", into: '/home/pi'
            }
        }
    }
}

Conclusion

This task is helping me save some time when deploying a Java application to a Raspberry Pi. I hope it helps you too!

As always, if you have not seen my other tutorials look at for example this on or this one. 🙂