If you’re a developer reading this, you’ve probably heard of Eclipse and Intellij IDEA, two integrated development environments (ides) that can be called magic pieces.

Eclipse is characterized by open source code, numerous plug-ins and convenient extension. It can be configured to support a variety of development languages and has a large number of users.

Intellij IDEA is divided into community and professional versions. Because commercial companies are maintaining and updating, the Professional version has richer features and is easier to use, but if you use the community version alone, you lose a chunk of functionality. Of course, today’s discussion is not about which IDE is better than the other, but rather a brief look at how Tomcat works between the two heavily used ides.


  1. Eclipse starts by taking a look at Eclipse and configuring it to add Tomcat that has already been downloaded locally to the Server. After that, Tomcat can be configured when deploying the Web application. Now, let’s see what’s going on behind it, by starting Log.




In the blue box above, you can see the file path of the tomcat webapps deployment directory and the command wtp.deploy. WTP is also a plug-in for Eclipse. Let’s follow this path and open it locally.





This is the upper level directory, and we can see that there are almost all of them except the Tomcat bin and lib directories. The conf file has these





You can see what the Tomcat configuration file looks like. Use the JPS command mentioned in the previous article to check the specific execution of the parameters, the basic understanding





In the preceding figure, -d is followed by the parameters passed when the JVM is started. Catalina. base represents the path where all these configuration files and other resources are searched when Tomcat is executed. All these configurations are resolved after Tomcat is started, so the configuration files in these independent locations can take effect.

What if you want to run more than one Tomcat in an IDE? Given the above analysis, you might say, so easy. Just specify different catalina.base and configure different cultures in their corresponding paths.

Yes, it affects whether more than one Tomcat, or by extension, multiple applications, can exist in an operating system at the same time, meaning that resources such as ports are not occupied. And Tomcat, in this public number of the third article analysis of specific internal components, server. XML can be configured Http channel, AJP channel these two are involved in the port, as long as the port number is different. Another thing that is often overlooked is that the port under the Server tag, by default, is 8005, which can also conflict. I need to be careful.


With the above analysis, we can sort things out. In Eclipse, Tomcat is implemented by specifying different Catalina.base to customize the configuration of different channel ports, application file deployment directories, and so on, which can be easily used within the IDE.

  1. Intellij IDEA

    Now let’s look at Intellij IDEA. When Tomcat is started, Log starts to see something similar to the following:





Note that the content in the blue box is basically the same as that in catalina.base. For the sake of rigor, take a look at the corresponding contents in this table of contents





As can be seen, the implementation ideas and the above analysis is basically the same, we will not talk more.

The difference between this and Eclipse’s plug-in implementation is that the wtP. deploy attribute is not specified, so there is no content of the application we want to run in the Webapps directory shown above. At this time, how does IDEA implement the deployment of the application?



In IDEA, when an application is deployed to Tomcat, the directory of the application is not found in the local Tomcat or the directory of the application is actually running. Careful observation shows that IDEA dynamically adds a Context, namely an application, to Tomcat through the MBean of Tomcat. This directly specifies the application path, access path, etc. For example, the following call chain:

TCP Connection(2)-127.0.0.1@1379 daemon, prio=5, in group ‘RMI Runtime’, status: ‘RUNNING’at org.springframework.web.context.ContextLoaderListener.<init>(ContextLoaderListener.java:98)at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1585)at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:463)at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:413)at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)at java.lang.Thread.run(Thread.java:745)

This invocation chain can also be observed because Tomcat’s MBeanServer cannot be accessed until tomcat is started. So here’s how to start an empty Tomcat.

main@1, prio=5, in group ‘main’, status: ‘RUNNING’at java.net.DualStackPlainSocketImpl.accept0(DualStackPlainSocketImpl.java:-1)at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)at java.net.ServerSocket.implAccept(ServerSocket.java:545)at java.net.ServerSocket.accept(ServerSocket.java:513)at org.apache.catalina.core.StandardServer.await(StandardServer.java:446)

at java.lang.reflect.Method.invoke(Method.java:483)at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)

Through the above simple analysis, the specific implementation principle of Tomcat in IDE has been clear.