• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28235
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1359
39
IBM DB2 Netbeans IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Bartender
Posts: 667
14
TypeScript Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28235
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic