Hi, I already have a Digital Ocean VPS that is hosting my static html portfolio website. I am making a REST API in Java (spring boot) and I will have an executable .jar. I want to deploy this on my VPS.

Can I create another Virtual Host in my /var/www directory, so I will have 2 Virtual Hosts on the same VPS?

Also, is running the Java .jar on the VPS as easy as FTPing the .jar over to the server, then simply running it as a service, i.e. systemctl start myjar?

Or are there more steps needed ? When I disconnect from ssh to my VPS, will the jar continue running? It’s an API with endpoints so its needs to be up 100% of time.

Thank you.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

OK , I figured this all out after 1 week of research.

So the first step is getting the server setup, for most Spring boot apps, this means installing Java on the server and some type of Database, I choose PostgreSQL.

  1. Install Java
  2. Install PostgreSQL (or your database choice)

Make sure to create the user and database that you will use for your connection string in your application.properties (or where ever your connection info is) or you won’t be able to connect to your Database and your app won’t run

Then you can build up your Spring boot application locally and package it into a FAT(executable) .jar file. Make sure you have the spring-boot-maven-plugin for that

  1. Then you can run in the terminal ./mvnw clean package -Dmaven.test.skip=true

Make sure your database credentials are inside your application.properties file or whatever file they need to be in before you package your code into a jar

  1. SCP your jar file to your Digital ocean. A director like /var/myapp works good.

You should have the Apache Web Server already installed and setup for a non-root user. Digital ocean has alot of good guides to set that up.

You can run your jar by typing:

java -jar yourjarfilename.jar

It should spin up and start successfully.

If you’re using a Spring Boot app that uses the embedded Tomcat server like me, since the Apache Web Server listens for HTTP on port 80, and the Tomcat default port is 8080, no traffic will be sent to your Tomcat server.

Thus , you will need to setup a reverse proxy so your Apache web server re-routes HTTP traffic to your embedded Tomcat listening on port 8080.
https://www.digitalocean.com/community/tutorials/how-to-use-apache-as-a-reverse-proxy-with-mod_proxy-on-ubuntu-16-04

Because I still wanted to use my frontend static website located at alpizano.me, that means I had to make the ProxyPass redirect at the which a /api route, or else it rerouted all my traffic and I was never able to access the root of my website at alpizano.me This could be want you want though, if you plan to have your main Spring boot/Tomcat server as your main application

You can then setup your Spring boot app as a Systemd service so that its managed by Systemd and runs even when you close out the SSH connection and logs to journalctl Read about that here
https://clouding.io/hc/en-us/articles/360010806999-How-to-Deploy-Spring-Boot-Application-with-Nginx-on-Ubuntu-18-04

Good luck!

by Mateusz Papiernik
In this tutorial, you will set up Apache as a reverse proxy using the `mod_proxy` extension to redirect incoming connections to underlying application server(s) running on the same network. There are instructions on setting up a simple web app using the Flask framework to show how Apache interacts with the real application hidden behind it, but you can also follow this tutorial using your existing application server, if you have one.
Submit an Answer