Maven Standard Directory Structure
Fast recall
Quick revision
Core answer
src/main/java, production resources in src/main/resources, tests in src/test/java, test resources in src/test/resources, and generated build output in target. These are defaults, not language rules; a POM can configure alternatives.Basic Maven project navigation — knowing where to put code, tests, and resources is fundamental for any Java backend work
Not knowing where to put application.properties or other config files — they go in src/main/resources, not in the java directory
Mention that Spring Initializr generates this structure automatically and that target/ is in .gitignore because it's generated output, not source code
Interview-ready guide
Interview answer
The normal Maven layout is src/main/java for production source, src/main/resources for production classpath resources, src/test/java for tests, and src/test/resources for test data. Maven puts compiled classes, reports, and packaged artifacts under target.
For example, a Spring Boot application.properties file is commonly a classpath resource under src/main/resources, while a deployment manifest used only by an external platform might live elsewhere. Maven plugins can configure custom directories, so the layout is not mandatory, but using the convention avoids unnecessary POM configuration and makes a new module immediately familiar.
Maven Standard Directory Structure
Direct Answer
Maven's standard layout places production Java in src/main/java, production resources in src/main/resources, tests in src/test/java, test resources in src/test/resources, and generated build output in target. These are defaults, not language rules; a POM can configure alternatives.
Code Example
// Maven standard layout for order-service project
order-service/
├── pom.xml // Project configuration
├── src/
│ ├── main/
│ │ ├── java/ // Production source code
│ │ │ └── com/company/order/
│ │ │ ├── OrderController.java
│ │ │ ├── OrderService.java
│ │ │ └── OrderRepository.java
│ │ └── resources/ // Config and static files
│ │ ├── application.properties
│ │ ├── data.sql // Schema initialization
│ │ └── static/logo.png
│ └── test/
│ ├── java/ // Test source code
│ │ └── com/company/order/
│ │ └── OrderServiceTest.java
│ └── resources/ // Test-specific configs
│ └── application-test.properties
└── target/ // Generated output (not committed)
├── classes/ // Compiled .class files
├── test-classes/
└── order-service-1.0.0.jar // Final packaged artifact
Common Mistakes & Pitfalls
- Putting config files in src/main/java: Freshers often create application.properties right next to their Java classes because that's where they're working. Resources must go in src/main/resources or they won't be included in the packaged JAR, causing "file not found" errors in production.
- Committing the target directory to Git: The target/ folder contains compiled bytecode and packaged JARs that are generated on every build. Freshers sometimes commit this 50MB directory, bloating the repository. Normally exclude
target/from version control — it's reproducible build output. - Creating custom directories like src/code or lib/: Fighting Maven's conventions by making up your own structure leads to hours of Maven configuration to tell it where to find things. Just follow the standard — every Java developer already knows it and Maven-aware tools understand it.
Check your understanding
Answer these without looking back at the article.
- Where does application.properties go in a Maven project?
- What is in the target directory?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.