Technical Blog Of JackCHAN

June 2, 2010

Using Maven In Eclipse/Myeclipse

Filed under: eclipse, hibernate, java, myeclipse, Spring, Technology — Tags: , , , , , , , — kaisechen @ 5:18 am

How to use maven to manage a web application in eclipse/myeclipse?

Firstly,we  need to install one kind of  maven plugin in eclipse/myeclipse.

There are three options which provide Maven integration for Eclipse/MyEclipse.

1)m2eclipse

http://m2eclipse.sonatype.org/, it is the most matured maven plugin for eclipse at the moment

2)Eclipse IAM

3)Maven4MyEclipse, which is base on myeclipse

Maven4MyEclipse and Maven-enabled MyEclipse projects co-exists with command line Maven use perfectly,Maven4MyEclipse was designed, however, to make command line Maven un-necessary in most instances, allowing you to stay inside the IDE and execute all Maven tasks from the UI.

The vice of maven4myeclipse is :

Maven4MyEclipse brings Maven support to MyEclipse Web Projects, MyEclipse EJB Projects, and conventional Java projects,MyEclipse Enterprise Application (EAR) Projects are not supported at this time, but should be in a future release.

Because i am using myclipse, i decided to use Maven4MyEclipse plugin,it is very easy to install it, let’s jump the step.

Secondly, we create a web project ‘Add Maven Support’ in myclipse.’

Thirdly, find the ‘pom.xml’ under the project, open it with ‘Maven POM Editor”

A POM(Project Object Model) is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects. Examples for this is the build directory, which is target; the source directory, which is src/main/java; the test source directory, which is src/main/test; and so on.

There are a lot of configues including Overview,Dependencies,Repositories,Build and so on.

Fourthly, we need install maven  and configue a local repository.

Download the maven from http://maven.apache.org, unzip it to any disk directory(e.g. D:\apache-maven-2.2.1). Modify settings file under conf(D:\apache-maven-2.2.1\conf).

Add one line:

<localRepository>D:/apache-maven-2.2.1/.m2/repo</localRepository>

Fifthly, configue maven4myeclipse in myclipse.

Open MyEclipse –>Preferences –>Maven4Myeclipse–>Maven–>Installations,

In User Settings,load the settings.xml in fouth step.

Sixthly,configue ‘Dependencies’ and ‘Repositories’  using ‘Maven Pom Editor’.

Add jboss repository if can’t find library in default maven repositories.

ID:org.jboss.repository.maven, URL:http://repository.jboss.org/maven2

After adding ‘dependencies’, the tool can produce a dependency graph.

In my project, i use spring mvc,hibernate etc. So the dependency graph looks like:

Seventhly, Deploy the web application into Tomcat/Jboss container.

Right click the web application, in popuped list, chose ‘Debug As’,chose ‘MyEclipse Server Application’, chose Tomcat or Jboss.

It is hot deployment, it is convenient to debug application.

Create a free website or blog at WordPress.com.