Running a Maven build means invoking the mvn command against a project's pom.xml from the command line, specifying the lifecycle phase or goal you want executed.
Key Points: • Navigate to the directory containing pom.xml before running any mvn command, since Maven looks for it in the current directory by default. • mvn compile just compiles source code, while mvn package additionally runs tests and produces a jar or war. • mvn clean package is a common combination that ensures a fresh, fully tested build artifact. • The -DskipTests flag skips test execution while still compiling test code, useful for faster local iteration. • IDEs like IntelliJ or Eclipse can trigger the same Maven goals through a GUI, but under the hood they invoke the same mvn command.
Example: From a terminal, cd into the project root where pom.xml lives and run mvn clean package to produce a fresh target/app.jar ready to run or deploy.
Interview Tip: A concise interview answer is:
"To run a Maven build, you go to the directory with pom.xml and run a command like mvn package, or mvn clean package for a fresh build. Maven then executes every phase up to and including the one you requested, in order."