Create a Maven Java SE Application in Apache NetBeans and Verify Incremental Build and Debug
Create a Maven Java SE Application in Apache NetBeans, configure Java Platform, Run and Debug, and verify incremental compilation works with practical checks and recovery steps.
25 Jul 2025, 09:36 UTC

Problem and takeaway
If you create a Maven Java SE project in Apache NetBeans and Run or Debug does nothing, the project is usually not recognized as a Maven Java Application or the Java Platform is missing. The useful takeaway is to create the project through Java with Maven -> Maven Java Application, confirm the Java Platform in Project Properties, and then verify Run, Debug and incremental compilation using the Projects pane, Output window and debugger.
Desired outcome
A new Maven Java Application visible in the Projects pane with sources under src/main/java, a editable pom.xml, and working Run and Debug actions without manual Ant scripts.
After creation you should be able to:
- Open pom.xml and see packaging jar and a main class referenced in the project.
- Run the project from the context menu and see program output in the Output window.
- Start Debug, hit a breakpoint in the main method, and see Variables and Call Stack populated.
- Save a source edit and have incremental compilation update the run without a full rebuild.
Prerequisites
Apache NetBeans installed with Java SE and Maven support enabled. A compatible JDK installed and registered in Tools > Java Platforms. A workspace folder with write permission and no name conflict for the new project.
Check the Java Platform before creating the project:
- Tools > Java Platforms.
- Confirm a JDK is listed and set as default. If not, click Add Platform and point to the JDK home.
Note on versions. Menu names and wizard layout differ between Apache NetBeans 19+ and older Oracle NetBeans 8.x releases. The steps below assume Apache NetBeans 19+ with embedded Maven. Embedded Maven can differ from an external system Maven in dependency resolution and plugin behavior.
Focused procedure
Create the Maven Java Application
- File > New Project.
- Categories: Java with Maven. Projects: Maven Java Application. Click Next.
- Project Name: . Project Location: . Create Main Class: check and use the default package and class name, e.g. com.example.App.
- Click Finish. NetBeans creates src/main/java, src/main/resources, target and pom.xml.
Confirm project structure and pom
Open Projects pane. Expand the project node. You should see Source Files under src/main/java, pom.xml, and Maven Dependencies.
Open pom.xml and verify basic packaging:
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>
If packaging is not jar or the compiler source/target does not match your Java Platform, edit pom.xml and save. NetBeans will prompt to reload the project.
Add or edit the main class
Open src/main/java/com/example/App.java. Ensure the class declares a public static void main(String[] args) method. Example structure:
package com.example;
public class App {
public static void main(String[] args) {
System.out.println("Hello from NetBeans Maven");
}
}
Configure run and debug
- Right-click project > Properties.
- Categories: Sources, check Source Package Folders includes src/main/java.
- Categories: Build > Compiling, confirm Compile on Save is enabled for incremental compilation.
- Categories: Run, confirm Main Class is set to com.example.App.
- Categories: Libraries > Java Platform, select the JDK you verified earlier.
Right-click project > Run. The Output window should show build activity and then program output. Right-click project > Debug to start the debugger.
Expected checks
Build output. After first build, the Output window shows Maven build steps and ends with BUILD SUCCESS. The Maven Dependencies node populates after the first build.
Run check. Run the project. Program output appears in the Output window under the Run tab. No manual Ant invocation is required.
Debug check. Set a breakpoint in the main method by clicking the gutter. Start Debug. The debugger should pause at the breakpoint and the Variables window shows runtime values and Call Stack is populated.
Incremental build check. Modify a source file, for example change the printed string, save the file. With Compile on Save enabled, NetBeans triggers incremental compilation. Run again and the new output is reflected without a full Clean and Build.
Limitation: Hot code replace in the debugger is limited to method body changes. Structural changes such as adding methods or changing signatures require a restart of the debug session.
Recovery options
If Run does nothing or the project is not recognized:
- Verify Java Platform in Project Properties > Libraries. A missing platform causes compilation errors.
- Validate pom.xml syntax. An XML error prevents Maven from loading the project. Open pom.xml and use the editor validation.
- Right-click project > Clean and Build. This resets artifacts in target and forces a full Maven lifecycle.
- If the IDE fails to recognize the project after edits, close NetBeans, remove the project from the workspace and reimport it, or reset userdir as a last resort.
Practical way to confirm the result: open Projects pane and confirm Maven Dependencies node populates after first build, set a breakpoint in the main method and verify debugger pauses with Variables visible, and modify a source file, save, and verify Run reflects the change without a full rebuild.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.