6
votes

I am planning to deploy a web application built on spring boot in windows server.

I want to use tomcat container.

Can I deploy the spring boot fat jar directly or is it recommended to deploy the war file.

please suggest how to deploy and the preferred method?

5
You need to get the basics right, spring boot is superset to tomacat servers, meaning it internally has tomcat server and it deploys your code on to it and runs up the server, so when you wrote an application in spring boot, you don't need to deploy it, just execute it, it will bring up everything for you.abdulrafique

5 Answers

2
votes

As Josh Long likes to say "Make Jar not War!" It really allows an application to have flexibility on where it can be run and allows for everything to be packaged as one artifact. Windows has no issue running the embedded Tomcat that is part of Spring Boot and that is exactly what it is doing when running it in your IDE. The one edge case to this is keeping the process running on the server. Normally in Windows you would do that by setting up a service and having that service run java -jar myapp.jar. I haven't personally seen it done so might take some playing around but it is possible.

1
votes

Starting from the latest Windows versions, you could also deploy your Spring Boot app inside a Docker Windows Container. I wrote a complete guide: https://blog.codecentric.de/en/2017/04/ansible-docker-windows-containers-spring-boot/ (as already mentioned, Tomcat is already embedded in Spring Boot).

1
votes

Spring boot internally has a tomcat server.

  1. If you want to deploy it on tomcat then while building with maven build it as war.
  1. If you want to deploy it has inependent application then build has jar and then place it in some folder and run it using below commands java -jar yourjarname.
1
votes

A simple way to run a spring application in Windows Server is to run it as a service. You can do it using the winsw, that you download its .bin file here winws download

Then, rename it to something like my-app.exe and create a XML file like this:

<service>
  <id>my-app-service</id>
  <name>my-app-service</name>
  <description>Back end service for app</description>
  <env name="HOME" value="YOUR_JAR_FILE_PATH"/>
  <executable>java</executable>
  <arguments>-Xrs -Xmx256m -jar "YOUR_JAR_FILE_PATH\YOUR_JAR_FILE.jar"</arguments>
  <logmode>rotate</logmode>
</service>

Then, using the terminal, run:

my-app.exe install service

Your application is now a windows service and you can start\stop it in the tasks manager on the services tab.

0
votes

Apache tomcat is a web container you cannot deploy a jar in tomcat server. If you created a web application then export your application as war file and put it in tomcat webapp directory, start the server and your war will be deployed.

How to deploy created .jar file in Apache Tomcat server in Eclipse IDE?