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.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
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.
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
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
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:
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 applicationYou 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-04Good luck!