1. Create, build and run locally the application
The application to deploy is a JPA Data with REST from the official spring docs. But, instead of the system wide gradle mentioned in the Spring documentation we'll be using the ./gradlew wrapper since this is the recommended way of doing things. The gradle wrapper is usually committed to the source control.
We are using Gradle, not Maven. A Gradle vs Maven comparison: https://dzone.com/articles/gradle-vs-maven and https://gradle.org/maven-vs-gradle/.
Clone the project and prepare:
We removed the remote github URL and became the sole owner of the project.
Next, let's have a look at the available gradle tasks and after that build and run the application locally:
2. Upload the jar and register the application as a service
Now we will upload the jar file to the remote Ubuntu server. For this purpose we should have created a VirtualBox Ubuntu 16.04 Server VM and installed Java on it.
After this we want our application to be easily started as Unix/Linux services.
Systemd is the successor of the System V init system, and is now being used by many modern Linux distributions.
On the server, create the
And add the following:
Start/stop/reload the service using the following commands:
To check if it's working do a system reboot and go to
http://vm_ip_address:8080/to see the result.
We have now a fully working Spring application that will start automatically on server reboot.
3. Spring application behind nginx
You can see now that the application is being served on port 80: