Configure Maven with Eclipse in AEM

The focus of this tutorial is to provide step by step examples and explanations to configure Maven , git , java with eclipse in AEM. This tutorial is for AEM beginners for setting up AEM workspace.

Topics covered in this tutorials:

Steps for installing and configuring Maven in Windows

  • Download  binary version of Maven from Maven Official Site.
  • Right click and extract the files into folder.
    extract maven from zip
  • Set the Environment Variable Paths.
    • Add M2_HOME and MAVEN_HOME.
      Note:- Apache Maven document suggest that only M2_HOME is sufficient but some software’s require MAVEN_HOME also.
      set M2_HOME eviromental variable
    • Add maven bin folder location to path system variable.
      set Maven path variable in windows
    • Verify Maven configuration.
      Verify maven configuration

Steps for configuring Maven Plugin (m2e) in Ecllipse

  • Download eclipse and unzip it.
  • Start Eclipse, set your workspace to something suitable (e.g. C:\Project\workspace).
    eclipse chooose workspace
  • Install Maven plugins(After eclipse Kepler version eclipse provide out of the box m2e plugin). Go to Help > Install New Software.
    eclipse install maven plugin
  • Select  ‘All Available Sites‘ in the Work with field.  Use the search field labelled as ‘type filter text‘ to find and select maven plugins  :
    • m2e – Maven Integration for Eclipse.
      select maven plugin in eclipse from all available site
      Note:- If by entering m2e in search bar no result is displayed. It means repository is missing with our ecllipse installation. Follow below steps to resolve the issue:
      m2e plugin search no result

    • Collaboration > m2e – Maven Integration for Eclipse
  • Click Next to continue.
  • Click ‘Next’ again and accept the terms and conditions for usage of the plugins.
    Accept maven plugin license
  • Proceed by clicking Finish accepting any unsigned content warning messages that appear.
    m2e pluging download progress bar
  • An install progress bar will appear and download the plugins. Once complete a message will appear asking if you would like to restart eclipse. Click No.
    restart eclipse after plugin installation

Steps for configuring Git in Windows

  • Download Git.
  • Double click the exe file and install Git.
  • Add Git cmd folder location to path system variable.
    set git enviroment path variable in windows

Building Maven Project in Eclipse

  • Download your AEM project code from any version control like GitHub or SVN into your local system.
  • Open eclipse –> Right click and select import.
  • Select Existing Maven Project from list. Click Next
    import existing maven project into workspace
  • Browse Root folder of AEM project  that you have downloaded from GitHub or SVN.
    import existing maven project into workspace in eclipse
  • Click Finish.
  • Open command prompt –> Go to the project root folder (C://users/<username>/git/<project-name>).
  • Run mvn clean install -p <AEM/CQ instance name>.

Trouble Shooting Maven Build Errors

  • If you face any caching issue delete the target folder from project.
  • While building Maven project you might get “Failed to execute goal org.apache.maven.plugins“.
    Note:- Root cause of this error is during installation of Maven any plugin was not installed properly.

    • Try deleting .m2 directory from (C://users/<username>/.m2) and re-run mvn command.
    • Try moving to lower Maven version , might be few properties are not supported in maven latest version by your project.

 

 

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Reply

Your email address will not be published. Required fields are marked *