how to stop tomcat in case of configuration loading failure - java

i have this error while launching tomcat
log from catalina.out
Unable to load specified config location file:/ .... startup failed:
Is there a way to make my java code cath this error and stop my tomcat ?

Tomcat will start up no matter what happens with the applications you expected to deploy. There is no feature to cause Tomcat to fail to start if your application fails to start properly.

You certainly do not what that feature - at least other Tomcat users do not want it. A ServletContainer can host multiple web applications, and I would not use a container that would stop simply because a deployment failed.
If a deployment fails, that perticular application is not started but others continue to run. It is up to you to fix the configuration problem and redeploy or manually stop the tomcat.

Related

RuntimeException when running Servlet: Tomcat restarting on its own

I am new to servlets and using Tomcat version 7.0.34 (we were instructed to use this version only). My problem is that the Tomcat seems to restart at some point of time, this occurs when I don't interact with the servlet for some time. I see the following:
.
Further when I tried debugging through eclipse I see the following entries in the debug window:
Daemon Thread [http-bio-80-exec-1] (Suspended (exception RuntimeException))
ThreadPoolExecutor(ThreadPoolExecutor).runWorker(ThreadPoolExecutor$Worker) line: not available
ThreadPoolExecutor$Worker.run() line: not available
TaskThread(Thread).run() line: not available
And this in console:
SEVERE: The web application [/csj] is still processing a request that has yet to finish. This is very likely to create a memory leak. You can control the time allowed for requests to finish by using the unloadDelay attribute of the standard Context implementation.
Okt 03, 2016 1:39:39 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/csj] is completed
I want to know the reason why Tomcat is restarting. If I keep clicking the buttons with no delays, then this problem is not seen.
I tried looking here: Tomcat showing this error "This is very likely to create a memory leak". How to resolve this issue? and here: The web application [ROOT] is still processing a request that has yet to finish. [Tomcat] but I am at loss to understand.
It seems this problem is solved in newer version of Tomcat as per this:http://wiki.apache.org/tomcat/MemoryLeakProtection . Nevertheless I would like to understand what is this problem about.
Edit: Using eclipse-mars
Your tomcat is configured for "hot deploy" i.e. if you change code, tomcat will incorporate new code without a server restart. This can be configured on tomcat, or in eclipse. You can go there and disable this as it is actually a headache and consumes more time, and sometimes doesn't work correctly.
Tomcat loads each webapp using a separate classloader. It monitors your files for changes, and if a change happens, it unloads your webapp by destroying the classloader, and loads again using a new class loader. When this is happening, you will see all kinds of logs as you mentioned.
For eclipse configuration, see here
For tomcat configuration, see here
Also, from Tomcat docs, read this
In server.xml, set reloadable="false".
From https://tomcat.apache.org/tomcat-5.5-doc/config/context.html
Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected. This feature is very useful during application development, but it requires significant runtime overhead and is not recommended for use on deployed production applications. That's why the default setting for this attribute is false. You can use the Manager web application, however, to trigger reloads of deployed applications on demand.

Tomcat webapp hanging on Bean Registration

I'm trying to deploy a war file that I put in the webapps directory. The logfile seems to indicate that everything goes OK until this step:
2015-08-10 16:33:25,944 INFO [MBeanExporter.java:412] : Registering beans for JMX exposure on startup
And it just hangs there until the server startup timeout hits. I have no idea what could be causing this or where to look since no error gets thrown.
The hangup was related to some issue other than JMX. See this userlist discussion: https://groups.google.com/forum/#!topic/onebusaway-developers/RDX1n8zVl4U

Illegal access: this web application instance has been stopped already. Could not load org.apache.log4j.spi.NOPLoggerRepository

I am using Netbeans 6.7 with Tomcat 6.0 and jasper reports for generating reports in a web application. I always get this exception when I run my application. can someone please help me out?
The exception is
INFO: Illegal access: this web application instance has been stopped already. Could not load org.apache.log4j.spi.NOPLoggerRepository. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1566)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.log4j.LogManager.getLoggerRepository(LogManager.java:175)
at org.apache.log4j.LogManager.getLogger(LogManager.java:199)
at org.apache.log4j.Logger.getLogger(Logger.java:105)
at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:283)
at org.apache.commons.logging.impl.Log4JLogger.info(Log4JLogger.java:193)
at org.hibernate.connection.DriverManagerConnectionProvider.close(DriverManagerConnectionProvider.java:147)
at org.hibernate.connection.DriverManagerConnectionProvider.finalize(DriverManagerConnectionProvider.java:142)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
It could be due to a memory problem, I had this message and also a
java.lang.OutOfMemoryError: Java heap space, adjusting startup parameters to:
-XX:PermSize=512M -Xms1024m -Xmx4096m solved the problem the problem.
I found I would get a similar error occasionally while running my JSP web application with Netbeans on Tomcat and always while debugging it. In my case it was "could not load Java.lang.math or Oracle.lnx.lib". A coworker had me undeploy the web application instances from tomcat and it solved the problem. To undeploy a webapplication instance, go to the Services Tab > Servers and then double click on Apache Tomcat or TomEE and after running the application once since opening netbeans, a Web Applications Folder should appear. If you double click on that, you should see instances of your application appear. You should be able to right click them and then click undeploy (you may have to right click them and hit stop first). Finally, you should stop and then start tomcat before building and running your application.
Hope this helps.

java.lang.NoClassDefFoundError: org/springframework/web/context/ContextCleanupListener

I have a webapp built using spring framework. I'm trying to deploy this to Tomcat6 using Eclipse. Everytime i make a change to jsp file, I had to clean the build, publish it & then start the server. I believe, we don't have to do all these steps for JSP changes. If i just publish the files, when the server is running, i get the below exceptions
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/web/context/ContextCleanupListener
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.util.Log4jConfigListener
java.lang.NoClassDefFoundError: org/springframework/util/Log4jConfigurer
And the war file is not getting deployed in server.
If I make a change to JSP file & then click restart in eclipse, it sometimes publish the files & then start the server. But in some cases, it restarts the server & then publishes the files (in which case i got the above mentioned exceptions & the war file was not getting deployed).
Ideal way that it works is, Stop the server, publish the contents & then start the server. I hate to do this every time i make a simple jsp change. Is there any alternate one click process to do this?
There's something wrong with the way you setup your project or server in Eclipse. I'd recommend following the instructions here. Also, you may want to download STS (Eclipse already bundled with Spring support) and use that instead of the vanilla eclipse.
Make sure that spring is deployed together with your application. Either set the correct export options in eclipse or copy the spring libraries to /WEB-INF/lib.
MyEclipse works fine here. You could also check JRebel as well. They advertise no redeployments. ;)
you can use exploded war and incremental hot-deploy.
this should work http://www.youtube.com/watch?v=OMtcjgTyP-g
folow at 2:30

"Error invoking method check" when deploying a WAR on Tomcat

When I deploy my WAR generated with Ant on my local system (copy/paste under /webapps), everything works fine.
The thing is, when I deploy the WAR on a remote server for test purposes, I got this error message:
There was an error thrown by Tomcat during deployment: "Error invoking method check". This however may not mean that you application failed to deploy. Please check the status in the application list
But the application is not deployed at all.
I have to use Probe (lambaprobe.org) to manage and deploy applications on Tomcat on the remote server I'm talking. And I don't have access to the filesystem, only probe.
Any idea would be much appreciated!
Thanks
I often encountered this problem and after checking the log this was caused by an OutOfMemoryError with tomcat
Impossible to check the log... We managed to restart tomcat and it works now.
Weird.
Thank you anyway!
Check the log files of tomcat; they contain the full error message.
If you can't access them easily, write a small webapp which allows you to browse and/or download the logs and deploy that.

Categories

Resources