I want to learn the internals of tomcat operation and understand the flow.
For this I created a servlet -
public class TestServlet extends HttpServlet {
//Breakpoint set on constructor
public TestServlet() {
}
}
I included the tomcat source code in source lookup directories and launched the server in debug mode. Following is the stack trace when debugger stops at my breakpoint -
Daemon Thread [localhost-startStop-1] (Suspended (entry into method <init> in TestServlet))
owns: StandardWrapper (id=39)
owns: StandardContext (id=40)
TestServlet.<init>() line: 12
NativeConstructorAccessorImpl.newInstance0(Constructor, Object[]) line: not available [native method]
NativeConstructorAccessorImpl.newInstance(Object[]) line: 39
DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 27
Constructor<T>.newInstance(Object...) line: 513
Class<T>.newInstance0() line: 355
Class<T>.newInstance() line: 308
DefaultInstanceManager.newInstance(String) line: 138
StandardWrapper.loadServlet() line: 1144
StandardWrapper.load() line: 1088
StandardContext.loadOnStartup(Container[]) line: 5123
StandardContext.startInternal() line: 5407
StandardContext(LifecycleBase).start() line: 150
ContainerBase$StartChild.call() line: 1559
ContainerBase$StartChild.call() line: 1549
FutureTask$Sync.innerRun() line: 303
FutureTask<V>.run() line: 138
ThreadPoolExecutor$Worker.runTask(Runnable) line: 886
ThreadPoolExecutor$Worker.run() line: 908
Thread.run() line: 662
As you can see tomcat initiates a new daemon thread to handle initialization of TestServlet
. If I step out from this position it would backtrace upto run and then stop. However I want to understand main server logic. What should I do to step into the org.apache.catalina.startup.Bootstrap
class? (or some other class that is run on main startup thread)
Access the Apache Tomcat console by browsing to http://localhost:8080/ (if installed as a non-root user) or http://localhost/ (if installed as the root user).
Have you installed Tomcat, you can launch Monitor Tomcat tool, and start the web service, Then open a web browser, and input in the address bar the URL http://localhost:8080, then you can view Tomcat documentation or start using Tomcat.
Use a browser to check whether Tomcat is running on URL http://localhost:8080 , where 8080 is the Tomcat port specified in conf/server. xml. If Tomcat is running properly and you specified the correct port, the browser displays the Tomcat homepage.
You can debug Tomcat as a remote Java application.
Here is the steps:
Create a CATALINA_BASE/bin/setenv.bat(or .sh) file and put following line into the file.
set JPDA_OPTS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y
Start the Tomcat in debug mode using catalina.bat (or .sh) from command line.
catalina.bat jpda start
From Eclipse, set up a Debug Configuration under Remote Java Application and connect to the Tomcat process. (Run -> Debug Configurations -> Remote Java Application.)
Screenshot:
Don't go for any of the confusing solutions. Found this after lot of research.
ant
command.new project
=> ava Project from Existing Ant Buildfile
=> point to tomcat source code
and
select build.xml
main()
method.and select
debug`Source not Found
, click add source
=>
java project
=> select the source project
There you go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With