Home > AOP, Apache, Maven, Spring > Start Spring with Maven & Eclipse

Start Spring with Maven & Eclipse

First download the latest binaries from apache. Then extract it and copy to C:Program Files. Now set the environmental variables as follows.

Then edit the path variable as follows .

Now verify the installation.

Then , create a project using maven.

Type the following command .

mvn archetype:generate -DgroupId=com.supun.common -DartifactId=SpringExamples 
-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

This will generate the folder with pom.xml file. Now open the pom.xml file. Edit the file so as it looks like below.

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">



Then convert this project into an eclipse project using mvn eclipse:eclipse. Then import it as follows.

Here is the folder structure.

Now add the following classes to the App class.

package com.supun.common;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

* Hello world!
public class App
public static void main( String[] args )
ApplicationContext context = new ClassPathXmlApplicationContext(Spring-Module.xml);
HelloWorld obj = (HelloWorld) context.getBean(helloBean);


And Helloworld java as follows.

package com.supun.common;
public class HelloWorld {

private String name;

public void setName(String name){
this.name = name;

public void printHello(){
System.out.println(Hello !+name);

Then create Spring-Module.xml inside the src/main/resources folder as follows.

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="http://www.springframework.org/schema/beans

 <bean class="com.supun.common.HelloWorld" id="helloBean">
 <property name="name" value="Supun">


Run the application
Here the output

Categories: AOP, Apache, Maven, Spring
  1. February 20, 2013 at 4:36 am

    It seems like u actually understand quite a lot
    pertaining to this subject matter and it exhibits
    thru this excellent blog post, given the name “Start Spring with Maven & Eclipse Technodyne”.
    Many thanks ,Eliza

    • supun dharmarathne
      February 20, 2013 at 6:04 am

      thankz mate .. 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: