This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization 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
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

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

 
Ranch Hand
Posts: 106
  • 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

 
Sheriff
Posts: 24374
55
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: 1120
38
IBM DB2 Java Netbeans IDE Spring
  • 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: 106
  • 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:

 
Ranch Hand
Posts: 374
2
Fedora IntelliJ IDE Spring
  • 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
Sheriff
Posts: 24374
55
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?
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!