How To Deploy Spring Boot Web Application To Production

Building web application is somewhat hard, but with good tools support, good programming language, and good framework, this daunting hard time consuming tasks can be minimized and can be somewhat fun.

Building web application using Spring Boot has many benefits, of course your gonna doing it faster, easier, large community support, and the beautiful maintainable codes. And the results of your web application performance, because it is Java technology, it can be fast, salable, and capable of handling thousands of thousands transactions.

This time i am not going to share java codes, it's just an easy simple tasks how you gonna deploy your application to production server. Of course there's lot of ways to do it, but for this time, i am only showing you 2 of the most easiest way to deploy your application.

1. Embedded Tomcat

This is the easiest way, basically you just installed Tomcat to your server, this is article to doing that How to install tomcat on Ubuntu. After that, login to Tomcat web application manager, then select your war file then hit deploy.

The problem with this method is whenever there is small problem in your codes, the only thing you can do is uploading those war files again. It is a big problem for efficiency because, mostly the war file you're gonna get is a big fat war file, it's gonna be over 20 MB at least, very not efficient if your application is constantly changing.

2. Run Jar File

This is the one i use, in simple way rather than building your application on your local computer, you can build your application on the server, then using java commands, run the jar file. So here's normally spring boot project structure looks like.

Simply run:
java -jar ./target/pos-0.0.1-SNAPSHOT.jar &

And you are done. You have a production ready web application running on the background. You can synchronize your code using git pull, and then build the jar on the server using "mvn install".

But somehow i don't understand, the jar file is not updated whenever we do mvn install, so our app is not updated even though we already have the latest code from our development repository. So every time you have new codes update, you should stop the running jar file, and then start it again. So we should create bash file to make easier.

For start your app, save as
java -jar ./target/pos-0.0.1-SNAPSHOT.jar & echo $! > ./pid.file &

To stop save as
kill $(cat ./pid.file)

For starting in silent mode
nohup ./ > start.out 2> start.err < /dev/null &

Make sure all the bash files executable, 
sudo chmod +x

Then whenever you have new codes, run this commands.
mvn install & ./ & ./


Popular posts from this blog

ERROR 1348 Column Password Is Not Updatable When Updating MySQL Root Password

Spring Kafka - how to use ReplyingKafkaTemplate send and reply synchronously

How To Create Spring Boot Project Using Netbeans

How To Connect SSH Using PEM Certificate On Windows

Intellij Error: Spring class file has wrong version 61.0, should be 55.0