I am working on a project, we are using Spring-Boot, STS. I just start the project with right click on main and run as spring boot app and it simply runs. Now I am asked to run it with Embedded tomcat on some other machine like Amazon EC2 instance. In normal spring project what I used to do is, create a war file, place in tomcat->webapps folder and start it from bin. In case of embedded tomcat how would I run my app without tomcat. where will my war(which includes embedded tomcat dependencies) run? Please suggest some solution, this is first time working with spring boot and embedded tomcat. Appreciate your suggestion.
4 Answers
Just pull in Spring boot tomcat starter, inside your pom or gradle build. This will bring all the tomcat dependencies to your app jar. Embedded tomcat means in runtime inside your JVM Spring boot starts a server with the dependencies in your jar. So all the problems of pushing the war to tomcat folder and restarting are eliminated. Build your jar using Spring boot plugin. mvn spring-boot:run or gradle bootRun and then just run this jar as any executable jar.
java -jar your-app.jar This calls the Spring Boot Main class. Which internally starts your server and creates your application context. This works for all platform, your local or EC2.
Comments
First, let me clarify about war and jar in the context of modern java web application development.
In the distant past, applications were written, packaged into .war files and deployed onto tomcat servers which ran on some OS like Linux. Usually these applications were big and reflected the whole business logic of some service, like a library site, which wholly depended on this one application that treated requests by generating a suiting response for each one of them.
With time, the web got bigger: More users + more data + stronger computers = more traffic. It got hard to keep this model of application development because It failed to serve reliably under high throughput traffic.
That's how Microservices were born. To keep a long story short: In Java, the best way to build microservices is by using spring-boot and the best way to deploy microservices is by using an embedded server for each microservice, like tomcat. Then these microservices are ideally deployed to the cloud (like AWS). Cloud services know how to deal with jars because jars are native to them.
Now, to your question, where will your war run? Your war won't run. Your jar will be executed by a cloud service and because It has an embedded tomcat dependency, It will run tomcat which will listen on default port 8080. This will be the gateway to your application that you built. The cloud service will probably allocate some DNS to your application and you will be able to communicate with It's embedded tomcat that way.
1 Comment
Convert it to jar using your IDE you are using..
Then :
On Windows, you have to set the java.exe(with full path) in the environment variable(with variable name = java). and then you can run java -jar "jar name with the full path"
If path is not set then what you have to do is : Example :
"C:\Program Files\Java\jdk1.7.0_67\bin\java.exe" -jar "jar name with the full path" - it will work 100% - check it out
thanks :)