Debugging JavaScript in Java web apps with NetBeans

NetBeans still ships a JavaScript debugger, and it earns its place when a Jakarta EE application spreads its logic across the browser and the server. The awkward bugs — a dropdown that never refreshes after an AJAX call, a form that posts an undefined field, a shopping cart that empties between screens — usually need a breakpoint inside a script the browser actually loaded, examined from the same IDE that holds your servlets and enterprise beans.

Most teams in Sydney, Melbourne and Brisbane still run Java web apps on GlassFish, Payara or Tomcat, with a JavaScript front end built by npm and bundled into the WAR. This guide covers creating that project, attaching Chrome or Firefox to the debugger, stepping between client and server code, and checking the quality of what you find. A few local notes appear along the way: GST on the invoice, privacy rules for log files, and daylight saving moving your timestamps.

Setting up a Java web app for debugging

Create a New Project with the Java Web App template, choose Jakarta EE and a supported server, then run the app so NetBeans deploys the WAR and starts the container. Local development usually stays on the default port, but shared test servers in Canberra and Perth often sit behind an nginx proxy, and the debugger needs an unobstructed route to the container.

Front-end assets decide whether breakpoints bind. NetBeans serves static files from src/main/webapp, so the files you want to break on — unminified output rather than app.min.js — need a stable URL the browser can request. If assets ship from a CDN, the browser is loading code the IDE never saw, so serve them locally or publish source maps that point back to your sources.

Plenty of Australian shops add Kotlin modules next to the Java code, particularly fintech teams around Melbourne. Adding the plugin and pointing it at an SDK takes minutes, as configuring NetBeans for Kotlin demonstrates, and once installed those sources break and watch just like JavaScript.

Attaching the browser to the debugger

Install the NetBeans Chrome extension or the Firefox add-on, grant it access to the sites you develop, and check that the browser tab carries the NetBeans badge. The browser then connects back to the IDE over a local socket; on corporate networks where outbound ports are filtered, allow the debug port through the firewall or use an SSH tunnel to a spare room in Ballarat.

Open the JavaScript file from the Project window, click the gutter to set a breakpoint, then reload the page. The editor shows where execution paused, while the Variables, Watches and Call Stack windows let you inspect the request object, the response body and everything in scope. Conditional breakpoints on values such as userId == null narrow the stop to the interesting case, and the Evaluate Expression window lets you call a function or poke a field without editing the file.

Breakpoints bind to the URL the browser requests, so a script loaded from another host or path will never hit. Keep one development URL, disable caching for the app host, and remember that a hard reload drops a paused session if the source changed underneath it. Plenty of developers still pick this work up after dinner with a flat white, so keep a stable browser profile and the same breakpoints waiting for you.

Stepping from client code into the server

Start the app in Debug rather than Run and the Java debugger opens alongside the JavaScript one. Set a breakpoint in a servlet, a JAX-RS resource or a session bean, trigger the same AJAX call, and the container pauses inside your Java code while the browser debugger stays attached. From there you can watch the request parameters the browser sent and confirm whether the payload arrived intact.

Asynchronous work makes this harder, because the thread handling a request is rarely the thread that rendered the page. The Threads window shows every suspended stack, and stepping a background thread into a shared cache is the fastest way to spot an overwrite. Debugging concurrent code is a skill of its own — a DenyHosts race condition shows how a breakpoint in a sync routine exposed a locking bug that reading the code alone had missed.

It helps to weigh the three workflows side by side:

Capability NetBeans JavaScript debugger Chrome DevTools NetBeans Java debugger
Breakpoint in a served script Yes, via the browser extension Yes Not applicable
Conditional breakpoints Yes Yes Yes
Watch expressions and call stack Yes Yes Yes
Pause inside a servlet during the same request Yes, with server debugging active No Yes
Minified bundles and source maps Partial, better with source maps Yes Not applicable
Setup effort Extension plus an IDE session None Included in the IDE

The practical split is that DevTools win for pure front-end work, the Java debugger wins for server-side faults, and the NetBeans browser debugger keeps both halves visible while a request is in flight.

Checking quality once the bug is fixed

A breakpoint proves where the fault lives; it does not prove the surrounding code is sound. Static analysis on the files you touched catches null dereferences and duplicated conditions before they reach production, and integrating NetBeans with SonarQube covers binding a project to a SonarQube server so the same rules run inside the IDE as in the build pipeline.

Log files need the same scrutiny. Anything holding names, addresses or card details falls under the Privacy Act 1988 and the Australian Privacy Principles, so redact before pasting a stack trace into a ticket. Bulk email triggered by a monitoring alert must clear the Spam Act 2003. Timestamps deserve care too: a container in Sydney running on daylight saving logs UTC+10 or UTC+11 depending on the week, while a contractor in Hobart stays on UTC+10 year round, so log in UTC and convert on display.

Australian teams buy tooling through local resellers, so invoices carry 10% GST and the licence terms arrive from a supplier trading under the Australian Consumer Law. Read them before renewing a debugger or analysis subscription for the team.

Then re-run the failing scenario, turn the breakpoint into an assertion in a unit test, and keep the reproduction script. A colleague in Perth should be able to run it on a clean checkout without a verbal walkthrough.

Habits that shorten debugging time

Good debugging is mostly preparation. The following routines cost little once adopted and save hours on the next strange bug.

  • Reproduce the fault in a fresh browser profile with the extension enabled, so stale cached scripts do not muddy the result.
  • Prefer conditional breakpoints on identifiers such as order IDs instead of broad stops on shared utility functions.
  • Debug unminified sources and ship source maps for production bundles, so line numbers match in both environments.
  • Log timestamps in UTC and convert on display, keeping daylight saving out of incident timelines.
  • Clear breakpoints, watches and suspended threads when you finish a session, or the next person inherits a paused container.
  • Write a short reproduction note — request, response, expected result — beside the test you add, so the fix survives your holiday.