background preloader

Maven

Facebook Twitter

Creation of Dynamic web project with Maven and Eclipse. Today I want to talk about Maven. It’s very powerful instrument and if you know how to use it you will make minimum effort to achieve maximum result. In general Maven helps you to manage a project including library dependencies, building process and etc… But in the article I’m going to show you one of the ways how to create a Dynamic Web Project using Maven (in Eclipse IDE).Pre-requirements: Eclipse IDE for Java EE DevelopersM2E plugin for EclipseMaven 1. File > New (Alt+Shift+N) > Dynamic Web Project Input some name for the project in the “Project name” field (e.g. mavenDWP);Select some “Target runtime” (I use Apache Tomcat 7.0);Click on the “Next” button;Create the following directory structure (please pay attention to the directory structure. Click on the “Next” button;Select the “Generate web.xml deployment descriptor” check-box;Click on the “Finish” button. 2. 3. Here is the final view of the Dynamic Web Project configured with Maven: That’s it.

Share and Enjoy. Java - Maven dependencies not being added to WEB-INF/lib. How to convert Java web project to Maven based project. There is no exact or official solution to convert an existing Java web project to a Maven based web application project. Basically, the Maven based project conversion will involve two major changes, which is : Folder structure – Follow this Maven’s folder structure.Dependency library – Put all your dependency libraries in pom.xml file. Steps to convert Java based –> Maven based This guide will show you how to convert the following servlet web application to Maven based structure, and support Eclipse IDE.

Existing Java web project structure A simple Java servlet web application , with one “javaee.jar” dependency library 1. Maven web project folder structure Create following new Maven’s folder structure. Move all exiting java source files to this folder – “\src\main\java“.Move “web.xml” file to this folder – “\src\main\webapp\WEB-INF“.Create a new “pom.xml” file, put it to the project root folder. See following diagram, this is how it look like after converted. 2. File : pom.xml 3. 4. 5. 6. 7. Java Dynamic Web project with Maven and Eclipse. How to create a Web Application Project with Maven. In this tutorial, we will show you how to use Maven to create a Java web application (with Spring MVC) project, and make it support Eclipse IDE. Tools used : Maven 3.0.5Eclipse 4.2JDK 6Spring 3.2.0.RELEASEDTomcat 7 1. Web Application Project from Maven Template In a terminal (*uix or Mac) or command prompt (Windows), navigate to the folder you want to store the project.

Mvn archetype:generate -DgroupId={project-packaging} -DartifactId={project-name} -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false This tell Maven to create a Java web application project from “maven-archetype-webapp” template. For example, $ pwd/Users/mkyong/Documents/workspace $ mvn archetype:generate -DgroupId=com.mkyong -DartifactId=CounterWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false[INFO] Scanning for projects... In above case, a new web application project named “CounterWebApp“, and the entire project directory structure is created automatically. 2. Pom.xml <! 3. Done. 4. Creating Dynamic Web Project using Maven in Eclipse. Eclipse Maven Web project. While using Maven as build tool in our project, I found it very difficult to create a Dynamic Web Project which supports Maven dependencies and can execute in Eclipse!

I have seen lot of people using Maven just as build tool and for local setup uses jar files in some /lib directory. I wanted to remove this dependencies on local /lib for jar files and resolve everything with Maven. My project should be a Dynamic web project with Maven dependencies enabled. Here is a simple tutorial which you can go through to create Dynamic Web Project having Maven enabled in Eclipse. This project can be used as base project and can be easily converted to most kind of project like Struts based, Spring MVC based etc. Required Tools For this tutorial, I assume you have following setup in your machine. 1. Step 1: Create Maven Project in Eclipse Create a new project in Eclipse. Enter “MavenWeb” as Project name and click Next. Once done, click Finish. Step 2: Generate Eclipse Project with WTP That’s it.