Win a copy of Microservices in Action this week in the Web Services 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Unable to Start Tomcat9 Programmatically - Stops at 'Creation of SecureRandom instance ...'  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

I am trying to create a basic web application to start building upon. I started from scratch with only Maven and the pom.xml. I am trying to embed Tomcat9 to bundle the whole application as a single JAR. The problem I am having is Tomcat doesn't seem to fully start. I'm not very knowledgable when it comes to setting up the logging, so in this scenario I'm not sure where to get more details on what's happening.

The last line in the log reads 'WARNING: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [175] milliseconds.' After this, nothing else happens.

I followed this tutorial (link below) for comparison and it ran successfully, so I tried to apply it to my program, but it's just not happening.
https://devcenter.heroku.com/articles/create-a-java-web-application-using-embedded-tomcat

I would appreciate any input on this, thanks!
The repo link for the project is below:
https://github.com/Wawawarrior/ddshop
Tomcat 9.0.10
Java Compiler 1.9


Here is the Main.java for quick reference:

 
Bartender
Posts: 19996
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically this is known as "embedded Tomcat", because the Tomcat server is embedded inside another application.

These days, you're actually probably better off using Spring Boot, since that's exactly what Spring Boot is for, so the work is mostly done for you.

However, check the logs. Not just stdout/stderr (catalina.out), but also look for logs/localhost logfiles. Many failures early in Tomcat startup are recorded there.
 
Wayne Woodrow
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the response, I will try that. Right now there are no log files so I think I need to figure out how to get that first. I assume they would be in the circled area (attachment) if they were being generated?

tomcatempty.png
[Thumbnail for tomcatempty.png]
 
Tim Holloway
Bartender
Posts: 19996
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know. In stand-alone tomcat, there's a conf/logging.properties file that defines where the logfiles go. In its factory version, they're placed under ${catalina.base}/logs.

catalina.base is assigned from the environment variable CATALINA_BASE, which is defined in the Tomcat startup scripts.

However, it's less clear how an embedded Tomcat would define logging. If it falls back to the JDK logging configuration, logging would go to the home directory of the user running the Tomcat application server.
 
Wayne Woodrow
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,

I started reading up on how to access the logging and tried a few different things, but I'm still not having any luck getting more information on why the startup ends where it does.

The code for my latest attempt is below. I retrieved the LogManager to get a list of all loggers. After checking that the loggers are not null, I set the level to ALL for each of the loggers listed, which seems to work okay. However, once I run the application, it doesn't seem to have any effect. I still get the usual INFO: and WARNING: messages but nothing else. I feel like there's another instance of a logger somewhere that I need to set to ALL, but if the LogManager doesn't see it then where would it be?

Any ideas would be appreciated. Attached is a screenshot of the console

console.png
[Thumbnail for console.png]
 
Tim Holloway
Bartender
Posts: 19996
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that in the normal course of events there should be a log message telling how long it took Tomcat to start.

As a precaution, I'd add a log message after the Tomcat "await()" call, just to ensure you know when Tomcat has shut down and returned to you.

Beyond that, it looks maybe hung up, so just wait a while and see if something times out and reports an error. And by "a while", I'm suggesting go make coffee or something, because it might be a LONG while!
 
Wayne Woodrow
Greenhorn
Posts: 15
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good afternoon,

So I have still been trying intermittently to get this to work, pulling from various examples (all on Tomcat versions other than 9), but I'm still getting the same result.

However, I had some slight success today in finding that the code below works with Tomcat 8.5, but not with Tomcat 9. So I guess there's an extra step or something different I need to do on version 9 to get this running, and I'm a little frustrated about that. But I am glad to at least have something working so I know I'm not completely off base.

See the attached images to compare the output. I think I'm going to keep messing with Tomcat 9 because I want to know why it's not working, so if you still have any tips I would be grateful for your input, thanks!


success.png
[Thumbnail for success.png]
failure.png
[Thumbnail for failure.png]
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was facing the same problem. I changed to embedded tomcat 8.5.23
Thank you so much buddy.  I wonder whats the problem with 9.0.10 though?
 
Sheriff
Posts: 5469
147
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wayne Woodrow,

Just a note about posting that will get you more help and quicker: don't post screenshots of text.  Instead, copy and paste the text.
 
Tim Holloway
Bartender
Posts: 19996
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed this earlier, but now I'm wondering. "Global web.xml not found."

You might want to research that.

Tomcat has a clever way to deal with URLs that have no explicit handler in a webapp. For example, directory listing and fetching images and other static content. It does that by using a built-in "default servlet" which contains the code that constructs the index pages and copies image resources to the response stream (with appropriate headers). A default servlet implies a default web.xml, so maybe there's something missing here. As I recall, in earlier versions of Tomcat, the default servlet was assigned from something in the Tomcat "conf" directory, and while I'm too lazy to check, it could have been an actual default web.xml file.

Yes, I know, recent enhancements have made it possible to code webapps that "don't have" a web.xml file, but web.xml is simply a spec file that gets digested into a collection of application resources, including the sub-URL routings, the security templates and so forth. Just because you can now do most of this stuff via annotations doesn't mean that the web.xml equivalent structure has gone away.
 
Wayne Woodrow
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your replies, and Noel I feel a little better knowing I wasn't alone on this.

Tim thanks for the additional information. I'm still trying to understand everything you said and how to go about figuring this stuff out... You referred to earlier versions of Tomcat, but I just wanted to mention quickly that 8.5 also shows the 'Global web.xml not found' message, but then continues to work. Below is the console output with the app starts:


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!