Maven is a great build tool. There are many resources out there describing this topic in detail. There are many examples of how to generate eclipse projects on this site however they cover the more advanced cases. This page describes how to generate a simple standalone project using a simple pom.xml file.
Quick History about Maven
Maven was originally started as an attempt to simplify the build processes in the Jakarta Turbine project. The developers of the Turbine project thought that this tool can be used to build any project and worked on generalizing it for use by the general development community.
A complete description about Maven is available here
Maven is used to Generate Eclipse Projects
On this site I use Maven to generate eclipse projects. The advantage for doing it this way is that the projecs are uniform no matter what platform they are on. Since the dependencies are well documented within the Maven’s main config file called pom.xml you dont need to worry yourselves with downloading them from third party websites.
A typical project will start by you the developer creating a new project. The second step is to place a pom.xml file (seen a the end of the post) into the main directory of the project. Then you will drop the command line and cd to the project’s folder and type mvn eclipse:clean eclipse:eclipse
Before you can start generating your own eclipse projects you need to install Maven. Please follow the instructions
Once that is complete you need to execute the following command
mvn -Declipse.workspace=<path to your workspace> eclipse:add-maven-repo
Once installation of maven is complete you can continue and create the pom file.
The following is the pom.xml file that was used to generate the above project
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>test</groupId> <artifactId>TestProject</artifactId> <packaging>jar</packaging> <version>1.0.1-SNAPSHOT</version> <name>TestProject</name> <build> <sourceDirectory>src</sourceDirectory> <resources> <resource> <directory>src</directory> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <configuration> <downloadSources>true</downloadSources> <downloadJavadocs>true</downloadJavadocs> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.5.5</version> </dependency> </dependencies> </project>
cd /workspace
mvn eclipse:clean eclipse:eclipse
verma@verma-desktop:~/workspace/TestProject$ pwd /home/verma/workspace/TestProject verma@verma-desktop:~/workspace/TestProject$ mvn eclipse:clean eclipse:eclipse [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'eclipse'. [INFO] ------------------------------------------------------------------------ [INFO] Building TestProject [INFO] task-segment: [eclipse:clean, eclipse:eclipse] [INFO] ------------------------------------------------------------------------ [INFO] [eclipse:clean] [INFO] Deleting file: .project [INFO] Deleting file: .classpath [INFO] Deleting file: .wtpmodules [INFO] Deleting file: .component [INFO] Deleting file: org.eclipse.wst.common.component [INFO] Deleting file: org.eclipse.wst.common.project.facet.core.xml [INFO] Deleting file: org.eclipse.jdt.core.prefs [INFO] Deleting file: org.eclipse.ajdt.ui.prefs [INFO] Preparing eclipse:eclipse [INFO] No goals needed for project - skipping [INFO] [eclipse:eclipse] [INFO] Using Eclipse Workspace: /home/verma/workspace [INFO] no substring wtp server match. [INFO] Using as WTP server : Apache Tomcat v6.0 [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER [INFO] Resource directory's path matches an existing source directory. Resources will be merged with the source directory src [INFO] Wrote settings to /home/verma/workspace/TestProject/.settings/org.eclipse.jdt.core.prefs [INFO] Wrote Eclipse project for "TestProject" to /home/verma/workspace/TestProject. [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1 second [INFO] Finished at: Wed Oct 28 21:31:31 EST 2009 [INFO] Final Memory: 20M/437M [INFO] ------------------------------------------------------------------------
Return to eclipse and click refresh on the project. You will now have a fresh new project with all the dependencies in the build classpath of the project. You will not need to download those from third party websites. Maven will retrieve them from the central Maven repository.

3 Responses to “Maven for Eclipse IDE Platform Developers”