Hosting a Java application: Tomcat on a VPS vs managed Java hosting
TL;DR: A Java application needs a JVM and something to keep it running. You either deploy a WAR file into Apache Tomcat, or run a self-contained jar (as Spring Boot produces) as a service under systemd. Both sit behind Nginx for HTTPS. A VPS with 2 GB of RAM is a realistic starting point for a small app, 4 GB for something busier. Managed Java hosting saves server work but limits versions and control. Pick a long-term-support Java release, and the Tomcat line that matches your code's namespace.
How Java hosting differs from PHP hosting
PHP hosts start a script per request and forget it. A Java web application starts once, stays in memory and serves many requests from the same running process. That brings good performance and a different set of needs: a JVM installed, enough memory for the heap, a process supervisor, and a front-end web server for HTTPS.
It also explains why general-purpose shared hosting rarely supports Java at all. Some hosts sell specific Java plans with Tomcat preinstalled, usually with tight memory limits and fixed versions. For anything beyond a small JSP site, a VPS is the practical answer.
Two ways to run a Java web app
WAR on Tomcat. You package the app as a WAR file and drop it into Tomcat's webapps directory. One Tomcat instance can host several applications, and the approach is familiar from older enterprise setups. It suits legacy apps and teams already comfortable with servlet containers.
Executable jar with an embedded server. Frameworks such as Spring Boot bundle Tomcat (or another server) inside the jar. You run java -jar app.jar and manage it as a service. There is no separate Tomcat to install or patch, deployment is a single file copy, and it is the more common choice for new projects.
Both models work well. Choose WAR on Tomcat when you inherit one or need to host several apps in one container, and the jar model for new work.
Choosing the Java and Tomcat versions
Java. Use a long-term-support release. The current LTS line includes Java 17, Java 21 and Java 25, so pick the newest one your framework and libraries support, and check each vendor's support dates. Avoid non-LTS releases in production because they are replaced every six months.
Tomcat. The Tomcat line you need depends on the API namespace your code uses:
| Tomcat line | Namespace | Minimum Java |
|---|---|---|
| 11.0.x | Jakarta EE 11 (jakarta.*) |
Java 17 |
| 10.1.x | Jakarta EE 10 (jakarta.*) |
Java 11 |
| 9.0.x | Java EE 8 (javax.*) |
Java 8 |
An app written for javax.servlet will not run on Tomcat 10 or 11 without migration, and the reverse is also true. Check the Apache Tomcat "which version" page for current support status before you decide.
Setting it up on a VPS
Start with a clean Linux server and work through our first ten things to do on a new VPS, including a non-root user, SSH keys and a firewall. Then:
- Install the JDK from your distribution's packages or a vendor build.
- Create a dedicated user with no login shell to run the app.
- Place the jar or WAR in a fixed directory such as
/opt/myapp. - Create a systemd service so the app starts at boot and restarts on failure:
[Unit]
Description=My Java app
After=network.target
[Service]
User=myapp
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/java -Xms256m -Xmx1g -jar /opt/myapp/app.jar
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
- Put Nginx in front with a proxy to the app's local port, and bind the app to
127.0.0.1so it is not reachable directly. - Add HTTPS and automate certificate renewal.
- Close the other ports with a firewall. Our UFW guide shows how.
- Rotate logs, because Java apps log verbosely. See log rotation on a VPS.
Memory sizing and the JVM
The JVM reserves a heap you set with -Xmx, and uses additional memory beyond it for metadata, thread stacks and buffers. As a rule of thumb, leave the machine room for the heap plus roughly the same again for everything else, including the operating system, Nginx and a database if it shares the box.
On that basis:
- Small Spring Boot app or a few JSPs: 2 GB of RAM with a heap of 512 MB to 1 GB.
- Busier application or one that shares the server with a database: 4 GB or more.
- Anything with large in-memory caches or heavy reports: size from measurement, not guesses.
Set -Xmx explicitly. An unset heap can grow to a large fraction of the machine's memory and starve other processes. Treat these figures as starting points and watch real usage, as described in our guide to server monitoring beyond uptime.
VPS or managed Java hosting
A VPS gives you full control over the Java version, Tomcat configuration, other services and cost. It needs server administration skills and a patching routine.
Managed Java hosting handles the server, usually with Tomcat preinstalled and a control panel for deployment. It suits small JSP or servlet sites and teams without server skills, with the trade-offs of fixed versions, memory caps and less flexibility if you outgrow it.
If you are not sure, start on a VPS when the app is business-critical, and on managed hosting when it is a small site you want to forget about.
FAQs
Can I run Java on shared hosting?
Only on plans that specifically offer Java or Tomcat. General PHP shared hosting does not, because it cannot keep a JVM process running for you.
Do I need Tomcat if I use Spring Boot?
No. Spring Boot embeds a server in the jar, so you run it directly. You only need a separate Tomcat for WAR deployments.
Why does my app crash with an out-of-memory error?
Usually the heap is too small for the workload, or the server has too little RAM for heap plus overhead. Raise -Xmx within what the machine can spare, or move to a larger plan, and check for memory leaks.
Which Java version should I install?
The newest long-term-support release your framework supports. Check support dates, and plan to move before a version leaves support.
Should the app listen on port 80 or 443 directly?
No. Run it on a local port and let Nginx handle ports 80 and 443 and HTTPS. This is simpler to secure and lets you serve several apps.
How do I deploy updates without downtime?
For a simple setup, upload the new jar and restart the service, which causes a brief pause. For zero downtime, run two instances behind Nginx and restart them one at a time.
Is Java hosting more expensive than PHP hosting?
Usually, because JVM applications need more memory than a typical PHP site. A VPS keeps the cost predictable.
Conclusion
Hosting a Java application means running a long-lived JVM process with a supervisor and a reverse proxy. Pick Tomcat for WAR-based legacy apps and an executable jar for new ones, match the Tomcat line to your namespace, use a long-term-support Java release, and size memory by heap plus overhead. A VPS gives the control Java apps usually need.
If you need a server for a Java application, see HostCloud's VPS options at https://hostcloud.in.
Sources:
