Recently, while contributing to a JRuby pull request (https://github.com/jruby/warbler/pull/572 on warbler), I was reminded of a classic piece of IT infrastructure: Tomcat. It's a common term, sure, but as a developer focused on rapid Ruby development and often dreading heavyweight deployments, I hadn't touched it in ages.
If you've ever had to quickly iterate on a JRuby WAR fileβthe kind that packages your Ruby application to run on a Weblogic βyou know the pain. It is very powerful, but heavy and opinionated. The installation is complex.
This is where the lightweight champion, Apache Tomcat, comes in. It's the perfect environment for quick testing, R&D, and prototyping. Let's see how you can set it up locally in minutes for your JRuby testing needs.
What is Tomcat?
Apache Tomcat is an open-source Java servlet container.
Crucially, it is not a full-fledged Java EE Application Server (like WebLogic, JBoss/WildFly, or GlassFish). This is the key to its speed and simplicity.
Tomcat specializes in running:
- Servlets (Java server-side programs)
- JSP (JavaServer Pages)
- WAR files (Web ARchives, packaged in a standard WEB-INF format)
Setting Up Tomcat Locally for WAR Deployment
If you are on Ubuntu, getting Tomcat ready is incredibly fast.
- Installation and Service Control The easiest way to install:
sudo apt install tomcat9
Once installed, you can manage the service with standard systemctl commands:
Action Command
A. Stop: sudo systemctl stop tomcat9
B. Start: sudo systemctl start tomcat9
C. Restart: sudo systemctl restart tomcat9
Key Folder Structure
For a typical Ubuntu install, the core directory is /var/lib/tomcat9
. Knowing these folders is essential for manual deployment:
- webapps/ β This is where you drop your WAR files!
- conf/ β Configuration files (server.xml, tomcat-users.xml).
- logs/ β Log files (look for catalina.out).
- bin/ β Startup/shutdown scripts.
Deploying Your JRuby WAR File π
This is the whole reason we're hereβthe simplest deployment process you'll find:
Build your JRuby application into a WAR file (e.g., using Warbler).
Copy the WAR file to the webapps directory:
sudo cp myapp.war /var/lib/tomcat9/webapps/
Restart Tomcat to trigger the auto-extraction:
sudo systemctl restart tomcat9
Tomcat will automatically extract your myapp.war into a folder called /var/lib/tomcat9/webapps/myapp/
. Your JRuby application is then instantly available:
β‘οΈ Access your application at: http://localhost:8080/myapp/
π» Optional: Using the Manager UI for Deployment
While the file copy method is fast, Tomcat also provides an easy web interface, the Manager Console, which is great for seeing the status of your deployed apps.
Important: By default, no login is configured, so you need to set one up manually.
- Set Up the Manager User You need to define a user with the manager-gui role in the configuration file:
sudo nano /etc/tomcat9/tomcat-users.xml
Add the following role and user definitions right before the closing tag. Remember to change the password!
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="mypassword!" roles="manager-gui,manager-script"/>
- Restart and Log In Restart Tomcat to load the new user configuration:
Bash
sudo systemctl restart tomcat9
Now, navigate to the console:
β‘οΈ Open: http://localhost:8080/manager
Use the credentials you just set up (admin/mypassword!) to log in. From here, you can deploy new WAR files directly through the UI without manually touching the file system.
in. From here, you can deploy new WAR files directly through the UI without manually touching the file system.
Conclusion
When is Tomcat the right tool?
β
Quick WAR testing (my use case for the JRuby PR).
β
Lightweight web apps where you only need Servlets/JSP.
β NOT when you need the full Java EE stack (transactions, enterprise security, messaging queues, etc.).
For developers working with JRuby, using a lightweight server like Tomcat dramatically cuts down the time between code changes and seeing results.
In my case, my prototype is a Rails application on JRuby but without Database, specially built for carry on the discussion.
I am not sure whether setting up oracle DB connection within Tomcat will work or not, if you have any idea, please share your thoughts, I will try a full-fledged Rails app with Oracle in Tomcat in coming days.
Top comments (0)