Search This Blog


Friday, May 7, 2010

maven setting up eclipse and on windows errors and using it errors

maven is kind of project management tool and that you will find everywhere
if you use eclipse generally you can keep the jars in classpath but using maven- creates a common repository on your local drive to keep all those jars so that you can use them easily in all the project and common to all project and for each project there is a pom defined which contain the version name and ids for jars
One thing more maven can also create a project in a proper way a hierarchy similar to eclipse creates a dynamic project or static project
point is if you are using eclipse you dont need everything to do just download a plugin and install it in eclipse just go on help tab on top in eclipse and go to install new software and add .There it downloads a plugin for maven to eclipse m2e now to configure it properly download maven the console version the zip file or any other and just extract it in C: drive
to step on command line just have to add some environment variables
and for this you should have already installed the java development kit
here are the environment variables to be added
add all of them to work for both eclipse and from console
add them in windows by going to MYcomputer right click and advanced >environment variables >just in system variable click add
C:\Program Files\Java\jre6\lib; for jre path it can differ just in classpath point it to jre lib and also add a colon in the end

C:\Program Files\Java\jdk1.6.0_19
no colon in the end in JAVA_HOME this is added so that maven can find tools.jar so its main requirement for maven
this is for maven running from console
C:\Program Files\Java\jdk1.6.0_19\bin;C:\apache-maven-2.2.1\bin;
just add these and MIND THE FOLDER apache-maven is the one where you have the console for the maven extracted after downloading from the website

Now just type on cmd mvn
if it works
and show thats good
test mvn -version
also test for java on cmd
type java

if it working than your maven is working from command prompt
now for eclipse there can be error like when building a project that
maven can 't find jre \tools.jar
so just go in eclipse
window>preferences>java>Installed jre and then add if no virtual machine added mean your eclipse should point to jdk so just check if its already added edit it and point it your jdk not the jre folder because maven looks for tools.jar which is in jdk not jre6

Now if you had configured everything is working fine but sometimes some dependency will be missing in your project or missing artifact than to installed separate jar
mvn install:install-file -DgroupId=groupid -DartifactId=artifactid -Dversion=version -Dpackaging=jar -Dfile="path to the jar on your local machine in double quotes " -DgeneratePom=true
this command on cmd and path for jar local machine should be with forward slash and in quotes

Invalid task 'build': you must specify a valid lifecycle phase, or a goa
e format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal

this error comes it must be a problem with your maven version or just

remeber to add
when you are adding a jar on local repository and also each time first clean maven by mvn clean
if still there is problem in missing any jar
just go in you repository location and delete the folder created wiith your related jar

to run from eclipse you need to add a file in m2 C:\Documents and Settings\(your account)\.m2 here settings.xml

copy this in settings.xml


just this and save
finally it works if not you can comment to ask me