Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

code not running when deployed as WAR in tomcat but runs fine as springboot app

 
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What could be the reason behind my following code which runs fine when I use the following path in Eclipse:

Right Click on Project -->Run As --> Springboot App

I can see this line of code printing the message from the ActiveMQ Queue.

However, when I deploy the project as a WAR into Tomcat, I don't see the same code running. I mean, the messages stays in the queue and doesn't get printed. I was expecting, as soon as I keep on adding the messages in the queue, it would keep on printing those messages but it's not working like this. What am I doing wrong here?

Here's my code (which is coming from here: https://javainsider.wordpress.com/2012/09/25/simple-guide-to-java-message-service-jms-using-activemq/#comments) :





And here is the pom.xml

 
Marshal
Posts: 25671
69
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jack Tauson wrote:However, when I deploy the project as a WAR into Tomcat, I don't see the same code running.



Tomcat expects you to write a web application, with servlets processing HTTP requests. You didn't write any such code, and rightly so because your requirements don't include HTTP requests. So expecting Tomcat to do anything with your code is a category error.
 
Bartender
Posts: 1268
39
IBM DB2 Netbeans IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spring boot allows you to build a fat jar and run it as a standalone application as well as build a war file meant to be deployed in a servlet container capable appserver as Tomcat. You need to change the class responsible for bootstrapping spring application context to achieve this (sorry, I don't remember by heart the details).
 
Jack Tauson
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Jack Tauson wrote:However, when I deploy the project as a WAR into Tomcat, I don't see the same code running.



Tomcat expects you to write a web application, with servlets processing HTTP requests. You didn't write any such code, and rightly so because your requirements don't include HTTP requests. So expecting Tomcat to do anything with your code is a category error.



Ok. Could you explain how come this piece of code runs properly? Here it's using JMS 2.0 instead of JMS 1.X that I am using in my code above:

 
Rancher
Posts: 527
6
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you put a war in a tomcat server it unpacks the war and makes servlets or something like that. Its not going to run like a regular application.
 
Paul Clapham
Marshal
Posts: 25671
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jack Tauson wrote:Ok. Could you explain how come this piece of code runs properly?



No, I can't. You didn't tell me anything about the context in which it runs. So how should I know?
 
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic