Create Maven project run eclipse

This demo will show you how to create maven project form command prompt and convert it to dynamic eclipse web project and run hello world from eclipse:

  • Download Apache Maven from here: http://maven.apache.org/download.cgi
  • After download extract it to any folder
  • Go to command prompt:  Click Window –>All Program –>Accessories –> Command Prompt
  • Once your command prompt is open go to directory where you have extracted Maven then set class path of maven bin as below:

Create Maven project run eclipse

  • To check if maven classpath set or not type mvn -version in command prompt as shown in above. It will show you Apache maven version.
  • Now we are all set to create Maven Project from prompt
  • From command prompt you could navigate to any directory wherever you want to create project for demo I have create workspace folder which is my eclipse workspace to create Maven project as below then enter following below command:

C:\Maven>cd C:\workspace

C:\workspace>mvn archetype:generate -DgroupId=com.javahonk -DartifactId=TestMavenWebProject -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

  • GroupId: Package structure
  • artifactId: Project name to be created.
  • maven-archetype-webapp: Maven type of project is web project
  • Press enter in command prompt: You will see first time it download jars to local directory and will create project with successful build as below

Create Maven project run eclipse

  • Now go to your workspace directory you will see TestMavenWebProject created.

Convert Maven project To eclipse project

  • In the command prompt go to your newly created project directory

Create Maven project run eclipse

  • Paste below
mvn eclipse:eclipse -Dwtpversion=2.0

 

  • After you enter you will see maven start converting project to dynamic eclipse project and lastly you will see build successful as below:

[INFO]
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time: 19.306s
[INFO] Finished at: Wed Jan 29 22:43:30 EST 2014
[INFO] Final Memory: 8M/20M
[INFO] ————————————————————————
‘cmd’ is not recognized as an internal or external command,
operable program or batch file.
C:\workspace\TestMavenWebProject>

  • Now maven project converted to eclipse dynamic web project

Import project into eclipse and run it and below are needed:

  • Eclipse 3.2 or above (Download eclipse from http://www.eclipse.org/downloads/ site)
  • JDK 1.6 or above (Download from here: http://www.oracle.com/technetwork/java/javase/downloads/index.html)
  • Tomcat 6 or above (Please follow link to install and configure tomcat in eclipse:Configure and Run Tomcat server in eclipse

Steps:

  • Open your eclipse –> Click File –> Import

Create Maven project run eclipse

 

  • Click General –> Existing Project into Workspace — Click Next

Create Maven project run eclipse

 

  • Click Browse  and select newly created Maven project from workspace then click Finish

Create Maven project run eclipse

 

  • Now you will see project imported in eclipse (As you could see below once project imported to eclipse it shows java error because Maven created dynamic web project of project facet version 2.4 with java version 1.4 that is not support by this project facet). To solve this issue Right click project –> Click properties –> Project facets –> Java then choose version 1.6 –> Click OK

Create Maven project run eclipse

 

  • This will resolve issue
  • Now it’s time to run this project. To run Right click project –> Run As –> Run on Server

Create Maven project run eclipse

 

  • Choose existing server –> Click Next (Note if you haven’t configure tomcat yet or not sure how to do it please click this link to configure tomcat in eclipse : configure tomcat in eclipse
  • Create Maven project run eclipse
  • Click Next it will open Add/Remove window add project right hand side configure window to run on tomcat server –> Click Finish

Create Maven project run eclipse

  • Great you will see project deployed on tomcat and it will show you Hello world! page. That’s it.

Create Maven project run eclipse

download2 Download project: TestMavenWebProject

Leave a Reply

Your email address will not be published. Required fields are marked *