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.
Always, refer to this Maven Standard Directory Layout for detail explanation.
See following diagram, this is how it look like after converted.

2. Project details
Fill in the existing project details in “pom.xml” file, add remote repository, war plugin and compiler plugin.
File : pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mkyong</groupId> <artifactId>serlvetdemo</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>serlvetdemo</name> <url>http://maven.apache.org</url> <repositories> <repository> <id>java.net</id> <url>http://download.java.net/maven/2</url> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <webResources> <resource> <directory>${basedir}/src/main/java</directory> <targetPath>WEB-INF/classes</targetPath> <includes> <include>**/*.properties</include> <include>**/*.xml</include> <include>**/*.css</include> <include>**/*.html</include> </includes> </resource> </webResources> </configuration> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> </project>
3. Configure the dependency libraries
This is the most annoying and time consuming session, you need to add your project’s dependency libraries in “pom.xml” manually.
Try find your project’s dependency libraries in Maven Central Repository , Java.net Maven Repository , or other remote repository. Patient… find the required Maven library code and include it into “pom.xml” file manually ![]()
For custom library, you need to install it into your Maven Local Repository manually.
See the “pom.xml” file again, after all dependency libraries are added.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mkyong</groupId> <artifactId>serlvetdemo</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>serlvetdemo</name> <url>http://maven.apache.org</url> <repositories> <repository> <id>java.net</id> <url>http://download.java.net/maven/2</url> </repository> </repositories> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> </dependency> </dependencies> <build> <plugins> <!-- Maven War file generator plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <webResources> <resource> <directory>${basedir}/src/main/java</directory> <targetPath>WEB-INF/classes</targetPath> <includes> <include>**/*.properties</include> <include>**/*.xml</include> <include>**/*.css</include> <include>**/*.html</include> </includes> </resource> </webResources> </configuration> </plugin> <!-- Maven compiler plugin --> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> </project>
4. Compile It – “mvn compile”
Compile it, Maven will download all the dependency libraries into your local repository.
E:\workspace\serlvetdemo>mvn compile [INFO] Scanning for projects... ....... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------
5. Make it Support Eclipse IDE
Almost done, now convert the new Maven based project to support Eclipse IDE.
mvn eclipse:eclipse -Dwtpversion=2.0
After that, you can import this project into Eclipse IDE.
6. Generate WAR file for deployment
Generate project’s WAR file with “mvn war:war“, the new generated WAR file will store in “/rootproject/target/” folder named “serlvetdemo-1.0-SNAPSHOT.war“, Maven will packed it along with the entire dependency libraries, classes and deployment structure automatically.
E:\workspace\serlvetdemo>mvn war:war [INFO] Scanning for projects... ....... [INFO] Processing war project [INFO] Copying webapp resources[E:\workspace\serlvetde [INFO] Webapp assembled in[47 msecs] [INFO] Building war: E:\workspace\serlvetdemo\target\s [INFO] ----------------------------------------------- [INFO] BUILD SUCCESSFUL [INFO] ----------------------------------------------- ...
7. Done
Your war file is ready for the deployment. And your existing Java web project is converted into Maven based project.
The whole conversion processes are mainly involve the folder structure and “
pom.xml“, this is all what Maven is required. The dependency libraries setting is very time consuming, especially when your project has more than 30-40 dependency libraries
Cheers for the example, very good and easy to understand. I only have one problem though
3. Configure the dependency libraries
is there no way Maven or Eclipse or anything can’t import from you lib folder or lookup the dependencies based on the jar names in this folder? It’s just I have 63 jars, Hibernate Spring Apache-Common JSF and a load more and not all (most in fact) I can’t find the maven dependency groupId/artifactId.
I don’t know any tool that can automate the process, try search your jar in http://search.maven.org/ , if it’s not, then include your jar in local repository and add it into pom.xml manually.
[...] You can then add the java based by following the instructions from this url: http://www.mkyong.com/maven/how-to-convert-java-web-project-to-maven-project/ [...]
[...] Here is a good tutorial show you 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 : [...]
[...] Convert Java web project to Maven project Here’s an article to guide how to convert an existing Java project to Maven style project. [...]
[...] 1) 2 Dec 09 – Article about How to convert Java web project to Maven project [...]
[...] a wrong folder in Eclipse Written on December 4, 2009 at 9:22 am by mkyong Recently, i had migrated a Java web project to Maven’s project. However the “web.xml” is always deploy to a wrong folder during Eclipse debuging [...]