#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
TestNG & Maven

Running A Maven Project Build Using Eclipse

Running a Build

Right-click the project in Eclipse, choose Run As > Maven Build, and specify goals such as clean test in the Goals field.

Common Maven Goals

  • clean — removes previously compiled files.
  • compile — compiles the source code.
  • test — runs the test suite.
  • package — bundles the project into a jar file.

Why Use Maven Builds Instead of Just Running a Class

A Maven build follows the full, repeatable lifecycle — ensuring dependencies are resolved and everything compiles before tests run, exactly as it would in a CI/CD pipeline.

Setting Up a Reusable Run Configuration

Typing goals each time works, but a saved configuration is quicker and avoids typos. In Eclipse, open Run > Run Configurations, right-click Maven Build and choose New Configuration.

  1. Name: something clear, such as "Smoke tests".
  2. Base directory: click Workspace and pick the project, which fills in ${project_loc:your-project}.
  3. Goals: for example clean test.
  4. Profiles: add a profile name if your POM defines one, such as qa.
  5. Parameters: add name and value pairs, which Maven receives as -Dname=value.
  6. JRE tab: select a JDK so compilation works.
  7. Click Run. Next time, pick it from the Run menu's history.

The Lifecycle Order and Useful Command Options

Maven phases run in order, and asking for one phase runs every earlier phase too. Running package therefore also validates, compiles and tests the project first.

PhaseWhat happens
validateChecks the POM and project structure
compileCompiles src/main/java
testCompiles and runs tests in src/test/java
packageBuilds the jar or war in target
verifyRuns extra checks such as integration tests
installCopies the artifact into your local repository

clean belongs to a separate lifecycle, which is why it is usually written first. The same goals typed in Eclipse work from a terminal as well:

mvn clean test                              # full clean build and tests
mvn test -Dtest=LoginTest                   # run one test class
mvn test -Dtest=LoginTest#validLogin        # run one test method
mvn test -DsuiteXmlFile=smoke.xml           # needs Surefire configured to read this property
mvn clean install -DskipTests               # build without running tests
mvn -o test                                 # offline, use only cached dependencies
mvn -U clean test                           # force update of dependencies

Reading the Build Output

The Eclipse console shows the same log as the command line. Scroll to the bottom first: BUILD SUCCESS or BUILD FAILURE tells you the outcome, and just above it Surefire prints a line with tests run, failures, errors and skipped. Failures mean an assertion did not hold; errors mean an unexpected exception was thrown.

Detailed results are saved in target/surefire-reports, including text and XML files for each test class. CI tools read those XML files to show trends, so the build you run in Eclipse produces exactly what a pipeline would publish. Refresh the project with F5 if the folder does not appear.

Fixing Common Build Errors

  • "No compiler is provided in this environment": Eclipse is running Maven with a JRE. Choose a JDK in the configuration's JRE tab or in Installed JREs.
  • "Could not resolve dependencies": check your internet connection or proxy, confirm the version exists, then run with -U.
  • Tests run: 0: test class names or folders do not match Surefire's defaults, or a TestNG suite file is not configured.
  • Project shows red marks but the build passes: right-click the project and choose Maven > Update Project to resync Eclipse with the POM.
  • Wrong Java level: set maven.compiler.release in the POM so Eclipse and Maven agree.

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course