Spring boot application in windows server - java

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?

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.

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.

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

Spring boot internally has a tomcat server.
If you want to deploy it on tomcat then while building with maven build it as war.
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.

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?

Related

Jar via Tomcat in IntelliJ

I spended a few hours to resolve my problem with deploying jar file on tomcat but I lost all fights, and I must ask one question:
Is it possible to run the jar file via tomcat in intelliJ?
Best regards
It's not possible deploy a jar in Tomcat anywhere. You can only deploy war files.
Normally when you distribute a web application in a jar (like a spring boot app) you don't deploy it in a server, it's a standalone application you run from the command line.

Using azure to run java app but access not working

I just started to work with the azure platform and I have a Question.
I upload my app to azure and run it but when I try to access it, it does not work but returns a 404 not found.
Maybe I did something wrong?
This is the repo that I connected:
https://github.com/idanovadia/ServerAlgoSearchImplementation_v2
for example when I run it on local host :
http://localhost:8080/getMaze/prim
now I tried :
https://searchnow.azurewebsites.net/getMaze/prim
I see that you try to package your java app to a jar file, and run the jar with a web.config in web app. This is the old way to run spring boot application.
In fact, there is a common and better way. It is just to package your spring boot application to a war package. And then you can deploy it to Azure web app with tomcat container.
1. You need to choose to package as war when you initialize the spring boot project:
2. Set the packaged file name to ROOT.war
Open the pom.xml, add the following line:
Then you will get a ROOT.war file if you run mvn clean package
3. Create a web app with Tomcat
4. Deploy ROOT.war under \site\wwwroot\webapps folder in web app
5. Restart your web app.

How to deploy Java application to Tomcat 8 App Service using Azure DevOps release pipeline?

I have a Java application that can be deployed to a Tomcat 8 App Service from Eclipse using the Azure extensions.
I created a Build pipeline that creates artifacts with the .war file.
I then created a Release pipeline and set up a "Deploy WAR to Azure App Service". The pipeline deploys the war file and expands it, but some other configuration is not right because the app is not available on the Tomcat server.
Has anyone used this task to successfully deploy to a Tomcat 8 App Service?
If so, what else needs to be done to get the app to deploy successfully?
P.S. I have very little experience with Java or Tomcat so it's likely something I've missed.
Well, seems you deployed the WAR to Azure App Service (Azure Website) but not the Tomcat server.
You just need to deploy the WAR to Tomcat server instead of Azure Website.
Build the Java project first, please refer to Working with Azure
DevOps and Java and Build your code with Maven for details.
Install the extension Apache Tomcat Deployment
Deploy applications to a Tomcat server using the Deploy to Apache Tomcat task.
Reference below articles to do that:
Continuous Integration and Deployment of Java web apps to Azure with
VSTS
https://github.com/Microsoft/vsts-tomcat/blob/master/src/tomcat.md
The Answer by Andy is most of the solution but there was one additional piece required to get the deployment working. I found this response to some additional errors I was getting after switching to the Apache Tomcat Deployment.
I also added a bash script to rename my app to ROOT cp my-war-file-name.war ROOT.war so that the app was the default application.

Running spring + hibernate application without actual servlet container

I have a Spring+Hibernate application, which I compile to *.war file and deploy it to Tomcat. This works for me as developer, but:
Is there a way to run that application in some user's computer, that has Java installed, but not tomcat installed?
I would even accept the solution, which uses somekinda package that actually runs the servlet container and deploys the application to user's computer, but I don't want that user must install container and configure it etc etc.
Any suggestions?
EDIT:
Basically I want user to run my web application from an executable, without having to install tomcat or other tools.
You have a few options:
if you are distributing the source code to the user, and they have maven installed, you can just run mvn jetty:run or mvn tomcat:run to build the application locally and run it within a servlet container started by the Maven plugin.
You can embed Tomcat or embed Jetty in your application, so that running a main() method in your app launches a servlet container listening on a certain port and runs your application. This makes it possible to package your entire application as a single .jar file and have it be run with java -jar your.jar.
The Winstone servlet container allows for embedding the war-file inside the winstone jar, resulting in a single jar deployment which can be run either with "java -jar foo.jar" or as a clickable jar.
Jenkins/Hudson uses this. We've used it with some classpath trickery to use an exploded war.
See http://winstone.sourceforge.net/#embedding for details.
This is most likely the most elegant way to do this at the moment.
You can certainly run a spring +hibernate application from command line, using the ClassPathXmlApplicationContext to load the spring configuration file in your main method to initialize the spring container and rest of the wiring.
However, to run a web application written using servlets or similar paradigms that use Java Servlet Specification, then you need a servlet container like Tomcat, AFAIK.
Not a direct example, but potentially useful example of something similar: http://www.zimbra.com/products/desktop.html and http://www.zimbra.com/products/zimbra-open-source.html

GWT app - deploying on Tomcat or any other servlet container

Is there a plugin for Eclipse GWT or any other method to automatically deploy and run GWT app on Tomcat (or any other Serlvet container)? For the moment the only method I know is copying the compiled classes into WEB-INF directory but this is an arduous work. Additionally you have to configure Apache Tomcat manually. I'd like to have something like in Eclipse Dynamic Web Project where you can run your servlets directly by spawning tomcat process.
Thanks
You could write an Ant task to deploy and run your GWT app. It could copy the files and then tell your servlet container to reload the latest files.
Is this what you are looking for: "How do I use my own server in hosted mode instead of GWT's built-in Jetty instance?"?
PS: You only need to copy the contents of the war folder once.
PPS: I'm assuming here you want to be able to easily deploy your app to Tomcat during development, since you are bringing up spawning Tomcat from Eclipse - meaning it's not a production server.

Categories

Resources