How to use NetBeans to create a Java web app with Tomcat

Apache Tomcat is a lightweight servlet container for Java web applications. NetBeans can create the project, manage Tomcat, launch the app, and attach a debugger. The result is a direct path from source code to an HTTP endpoint that a browser or automated client can exercise.

Start with a supported JDK, a NetBeans release that includes Java web tooling, and a compatible Tomcat version. Menus vary slightly between releases, but the sequence remains stable: create a Java web application, register Tomcat, add request-handling code, and run the project. The classic Java with Ant wizard suits a small servlet app; Maven is usually stronger for reproducible dependency management.

In Sydney, Melbourne, or Brisbane, developers can run the stack locally, so the first test needs no cloud account. That reduces latency and cost while startup faults are diagnosed, particularly for Australian teams working across sites and time zones.

Prepare NetBeans and Apache Tomcat

Install a supported Long-Term Support JDK, then NetBeans with Java web application support. Download Tomcat separately because NetBeans manages the container but need not own its installation. Record the three versions in a development-tools folder so another engineer can reproduce the setup.

Open Services and choose Add Server, or use the equivalent Servers panel in some releases. Select Apache Tomcat, point NetBeans at its home directory, and let it create a local base directory. Check the HTTP and shutdown ports because 8080 and 8005 are common defaults and may already be occupied.

Match Tomcat to the project’s servlet namespace. Tomcat 10 uses jakarta.servlet, while Tomcat 9 uses javax.servlet; mixing them causes compilation or startup failures. Older walkthroughs still explain the overall arrangement, and the site’s archived NetBeans articles provide useful version-specific background.

Create the Java web application

Choose File > New Project > Java with Ant > Java Web Application for IDE-managed deployment. Enter a short project name, a package such as au.com.example.stock, and select Tomcat. NetBeans generates the WAR structure, source folders, tests, and deployment descriptor. A name without spaces gives a cleaner local URL.

For Maven, create a Maven Java Web Application and keep the selected server for IDE deployment. Declare the relevant Jakarta or Java EE dependencies and WAR packaging in pom.xml. This suits teams that publish Maven artefacts internally or build the same project in a continuous-integration pipeline.

Choose the project type by its long-term build process rather than convenience alone. Developers can later add custom NetBeans plugins to remove repetitive editor tasks, but the basic project should run before extensions complicate the setup.

Add a servlet and a simple page

Add a Servlet class and map it to a URL. With a current API, use @WebServlet("/stock") and import matching HttpServlet types. In an older project, add the mapping to WEB-INF/web.xml. Keep the URL stable because browsers, mobile clients, and tests will depend on it.

The handler can read a parameter, return plain text, and set the response content type. Use response.getWriter() to write the body, and validate input before using it in a database query. Do not expose stack traces or server paths to users; application checks are needed even when the endpoint starts as an internal tool.

Create index.jsp as a welcome page, or map a controller to /. Define welcome files and mappings through annotations or web.xml. Test the root page and servlet because successful compilation does not prove Tomcat loaded the application without a duplicate mapping or missing dependency.

Run and debug the application

Right-click the project and choose Run. NetBeans builds the WAR, starts Tomcat if needed, deploys the application, and opens the default browser. The usual address is http://localhost:8080/ProjectName/, although the context path depends on the project name. Treat this as a development endpoint, particularly when colleagues access it through a company firewall.

Use Debug Project when the request path is unclear. Set a breakpoint in the servlet, call the endpoint again, and inspect request parameters. Tomcat’s console output and log files reveal startup errors hidden by the browser. Common causes include a wrong servlet namespace, occupied port, invalid XML, or missing dependency.

A sound security default is to deny access unless a request is explicitly permitted. The rationale behind default deny thresholds also applies at the application boundary: protect administrative routes, limit HTTP methods where practical, and keep sensitive configuration out of source control.

Package and deploy the WAR

Choose Clean and Build to create the WAR artefact under target for Maven or the build directory for Ant. Confirm that it contains classes, JSPs, descriptors, and libraries, but no credentials or local-only settings. A repeatable package gives another engineer or deployment team the same application structure.

For a local server, copy the WAR into the Tomcat instance’s webapps directory or use Tomcat Manager with authorised credentials. In managed hosting, upload the WAR through the provider’s console and configure the context path, database access, logs, and environment variables. CATALINA_HOME identifies shared Tomcat binaries, while CATALINA_BASE identifies the instance-specific configuration and deployed applications.

The servlet design can coexist with newer API styles. If GraphQL subscriptions are later required, compare the model in Fastify GraphQL subscriptions with the Java stack. Many Australian small businesses buy managed hosting rather than run Tomcat, so confirm whether the WAR is deployed directly, sits behind Apache or nginx, or moves into containers.

Keep the workflow secure and repeatable

A documented local setup speeds support and prevents the app working only on one workstation. Keep developer configuration separate from production settings, record ports and environment variables, and use Australian English such as “artefact”, “behaviour”, and “authorised”. Australian teams can then follow the same instructions without relying on informal explanations.

These practices keep the project suitable for a real release:

  • Pin the JDK, NetBeans, and Tomcat versions.
  • Store secrets outside the source tree.
  • Test each servlet mapping and expected response.
  • Check Tomcat logs after every deployment.
  • Build the WAR in CI before staging.
  • Restrict manager and administrative endpoints.

Together, these checks provide a traceable path from a NetBeans project to a running application. A clean build, successful Tomcat deployment, and repeatable request test form the local milestone.