Apache Maven is used for software project management. It uses the project object model (POM), and using that maven manages the build, reporting and documentation from a single place.
Steps to Create Maven Project with Eclipse
Download Maven
- Download Maven from http://maven.apache.org/download.cgi
- Open conf/settings.xml and replace localRepository with <localRepository>C:/.m2/repository</localRepository>. This is the place where all the downloaded artifacts will be stored.
- Add the following environment variables.
M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.0.3 PATH=C:\Program Files\Apache Software Foundation\apache-maven-3.0.3\bin
- To test Maven is working or not, Open command prompt and enter mvn. You will see as below.
- Add Eclipse Plugin for Maven
- Open eclipse and go to Help->Install New Software
- Enter the following in the first tab.http://download.eclipse.org/technology/m2e/releases/1.0/1.0.200.20111228-1245
- Check the box Maven Integration for eclipse and install the component.
- Click File->New->Other. In wizards, enter maven,select maven project and click next
- Then check the tab "create a simple project", and click Next.
- Fill the form as follows.
- Give Next and Finish.
- Now the Maven project is created with one artifact named test.
- You can see the below structure in eclipse
- pom.xml will tell about the artifact name and the package type.
- Now create web.xml and index.html as below
- Add these statements in web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>test</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
and index.html,
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>First Maven Web</title>
</head>
<body>
Welcome to Maven!!
</body>
</html>
- Now right click on test and do "Maven install"
- In the console you can see the message, Build Success
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ test ---
[INFO] Installing C:\Users\Sivaranjani D\workspace\test\target\test-0.0.1-SNAPSHOT.war to C:\Users\Sivaranjani D\.m2\repository\test\test\0.0.1-SNAPSHOT\test-0.0.1-SNAPSHOT.war
[INFO] Installing C:\Users\Sivaranjani D\workspace\test\pom.xml to C:\Users\Sivaranjani D\.m2\repository\test\test\0.0.1-SNAPSHOT\test-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.773s
[INFO] Finished at: Fri Aug 30 17:39:35 IST 2013
[INFO] Final Memory: 10M/121M
[INFO] ------------------------------------------------------------------------
- Now check your target folder, where you can see the built web application ready for use.
No comments:
Post a Comment