Spring boot application in windows server
Asked Answered
P

5

8

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?

Ph answered 12/8, 2016 at 0:43 Comment(1)
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.Guttapercha
O
3

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.

Octoroon answered 12/8, 2016 at 1:11 Comment(8)
Previously I deployed the spring boot jar in heroku cloud (unix). Will there be any advantage of unix system over windows for spring boot. Ref : docs.spring.io/spring-boot/docs/current/reference/html/…Ph
That is what I was talking about. I am not that strong at Windows server administration so not sure how to create services similar to how you set up an init.d script for Linux. You will have the same ability to define your environment settings through the command line to help tweak things.Octoroon
I usually create the spring boot jar file using the maven clean install. As the jar does not contain the html and javascripts. Do I have to keep the entire work space in the windows server along with the executable jar to run the web pages.Ph
If you are using the standard folder structure of a Spring Boot project then it should include those files. See my answer here to see if it helps: https://mcmap.net/q/1468785/-manually-launched-spring-boot-application-from-jar-not-working-properly. If the html and javascript files are not actually in the project directory structure then I am not sure what your usual process would be to add those files when deploying to Heroku.Octoroon
heroku has a git repository where I push my application, which builds the jar using maven and as the workspace is present along with the jar, Its work great. In the present case I think I have to either keep my web files in resources folder or use maven resource plugin to include my web app.Ph
I want to use angular 2 for the front end and spring boot for the backend. Can you suggest me the best way to package the application and its structure.Ph
I would post that as a new question and get some feedback that way. The original question was around having your spring boot running on windows which has been answered.Octoroon
Where do you the put the .jar file and how will it run when the server's IP address or domain is visited? I just get a 403 error.Shier
S
3

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.

Self answered 18/12, 2020 at 19:23 Comment(2)
credits to rodrigonunesdev.wordpress.com/2017/03/23/…Self
Is it possible to use nssm.exe to create windows service?Helluva
C
1

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.
Cachou answered 12/8, 2016 at 2:6 Comment(0)
M
1

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).

Marceline answered 8/4, 2017 at 7:33 Comment(0)
B
0

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?

Brittni answered 12/8, 2016 at 0:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.