1.
Starting Tomcat from the Terminal
Because clicking on icons is for the weak.
|
|
If this doesn’t work, check your Java installation… or just start praying.
2.
Stopping Tomcat Properly
Because kill -9
should not be your default debugging tool.
|
|
If Tomcat refuses to shut down, then you may proceed with extreme prejudice using kill -9
.
3.
Changing the Default HTTP Port
Tired of port 8080?
Want to make your co-workers hate you by switching it to something else?
Edit conf/server.xml
:
|
|
Congratulations, you have now successfully confused everyone who uses your server.
4.
Enabling HTTPS on Tomcat
Because security is not optional (even if configuring it is a pain).
|
|
Don’t forget to restart Tomcat and sacrifice a small offering to the SSL gods.
5.
Deploying a WAR File Manually
Because automation is overrated.
|
|
Or, if you’re fancy, use Tomcat’s built-in manager (but who has time for GUIs?).
6.
Checking Active Tomcat Processes
For when you have no idea why Tomcat isn’t responding.
|
|
If you see multiple instances, well… good luck.
7.
Setting Up a Basic DataSource for MySQL
Because hardcoding database credentials is for amateurs.
|
|
Put this in conf/context.xml
, restart Tomcat, and hope for the best.
8.
Rotating Logs Like a Pro
If your catalina.out
is bigger than your hopes and dreams, it’s time for log rotation.
Create a new logrotate config:
|
|
Add this magic:
|
|
Now your logs won’t take over your hard drive (hopefully).
9.
Setting JVM Options for Better Performance
Tomcat loves memory, so give it what it wants.
Edit setenv.sh
or setenv.bat
:
|
|
Because a well-fed Tomcat is a happy Tomcat.
10.
Reloading Context Without Restarting Tomcat
Because sometimes, you just need a quick refresh.
|
|
This will trigger a reload of the context without bringing the whole server down.
Magic!
✨
Key Ideas
Slug | Summary |
---|---|
10-apache-tomcat-code-snippets | Useful Tomcat code snippets for devs & admins |
tomcat-https | How to enable HTTPS on Tomcat |
tomcat-memory-config | Setting JVM memory options for performance |
tomcat-log-rotation | Keeping Tomcat logs under control |
tomcat-deployment | Deploying WAR files manually |
References
- Official Apache Tomcat Documentation
- Tomcat Configuration Guide
- Log Rotation Best Practices
- Tomcat Memory Tuning