There are no exact solution provide for the Maven project conversion. Here’s my thought on the Maven project conversion, basically the Maven project conversion will involve two major changes in existing Java web project.
1) Folder structure
- Follow Maven’s folder structure
2) Dependency library
- Put all the dependency libraries in pom.xml file
I will demonstrate the conversion from Java web project to Maven project. Btw, i’m using Eclipse IDE.
Existing simple Java web project structure
A simple Java servlet web application , with one “javaee.jar” dependency library

Steps of the conversion
1) Create Maven web project folder structure
- Create the following new Maven’s folder structure
- Move all exiting java source files to the “\src\main\java”
- Move “web.xml” file to the “\src\main\webapp\WEB-INF”
- Create a new xml file named “pom.xml” , put under the project root folder.
Please refer to Maven Standard Directory Layout
\--projectname
\--src
\--main
\--java (all java source here)
\--test
\--- (all unit test here)
\--webapp
\--WEB-INF
\--web.xml
2) Fill in the project information
- Fill in the existing project information in “pom.xml” file, add common remote repository, war plugin and compiler plugin.
<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 Maven library code and include it in “pom.xml” file
P.S For custom library, you need to install it into your Maven Local Repository manually.
Full Maven “pom.xml” example – with dependency library
<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 and make sure build is successful. Maven will download all the dependency libraries into your local repository now.
E:\workspace\serlvetdemo>mvn compile [INFO] Scanning for projects... ....... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------
5) Update Eclipse setting – “mvn eclipse:eclipse”
- Update the existing Eclipse setting, all the previous Eclipse errors will gone
E:\workspace\serlvetdemo>mvn eclipse:eclipse [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'eclipse'. ............... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2 seconds [INFO] Finished at: Wed Dec 02 17:48:24 SGT 2009 [INFO] Final Memory: 7M/14M [INFO] ------------------------------------------------------------------------
6) Generate WAR file for deployment – “mvn war:war”
- 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 pack it with all dependency libraries, classes and create the 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] ----------------------------------------------- ...
6) Done, deploy your Maven war file
The whole conversion processes are mainly involve the folder structure and “pom.xml”, this is what Maven is required. The dependency libraries setting is very time consuming especially if your project has 30-40 dependency libraries, convert it with patient
. Hurry up , convert your existing old Java project to Maven now!
For Eclipse IDE users only
After the migration, you may find out Eclipse will deploy your “web.xml” file to a wrong folder during debugging session. This is cause by the Eclipse deployment setting. you have to update the Eclipse deployment setting file as well , check this.
For Eclipse Dynamic web project
If you want to convert the Maven project to Dynamic Web Project in Eclipse, make sure the packaging element in “pom.xml” is “war” and issue the following command.
mvn eclipse:eclipse -Dwtpversion=1.5
Check here for detail about how to use Maven to create a Dynamic Web Project in Eclipse.


[...] 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 [...]