How to Create a Java Project with Maven in Eclipse
August 22, 2013
We will create a java project with maven in eclipse. We will start from scratch and learn step by step. 1. Install Maven in your Window Click Here
2. Install Maven in eclipse Click Here
3. In eclipse we will create a simple java project for demo. I have created a java project named as JavaProject in my eclipse. There is a class TestLogger.java . In our demo , there will be a apache logger to print the a message.
TestLogger.java
package com.concretepage; import org.apache.log4j.Logger; public class TestLogger { public static void main(String[] args) { Logger logger = Logger.getLogger(TestLogger.class); logger.info("Hello World!"); } }
pom.xml
<?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>com.concretepage.app</groupId> <artifactId>commonapp</artifactId> <version> 1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>Java App with Maven</name> <dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> </project>
log4j.properties
log4j.rootLogger = DEBUG, A # Set the appender named A to be a File appender log4j.appender.A=org.apache.log4j.ConsoleAppender # Define the layout for A appender log4j.appender.A.layout=org.apache.log4j.PatternLayout log4j.appender.A.layout.conversionPattern=%m%n
7. Configure project .classpath for new downloaded jar by pom.xml Maven does this by a command. Go to project directory and run command
mvn eclipse:eclipse
9. Find the package structure in eclipse.

Download Source Code
how-to-create-java-project-with-maven-in-eclipse.zip