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 :

  1. Folder structure – Follow this Maven’s folder structure.
  2. 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

Existing Java web project structure

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Ran Cohen
Guest
Ran Cohen

I’m with caroline – Where is the guide?

kaushik Lele
Guest
kaushik Lele

It seems article has been deleted. There are no steps given after screenshot of Java project.

Ernesto Maytin III
Guest
Ernesto Maytin III

For me the undeniably Eclipse; like NetBeans i have been doing extremely well at the time of compiling; easy and without complications.

Ernesto Maytin III
Guest
Ernesto Maytin III

Excellent; I have worked with some applications and it seemed to me a very useful tool when compiling my codes love JAVA.

Sukeerthy Anga
Guest
Sukeerthy Anga

I want to create a dynamic web project in eclipse using spring framework+hibernate without using maven and annotations.I already did the project using servlets and jsp.
Can u help me in developing the project?

Sundeep
Guest
Sundeep

Hi Mkyong, firstly thank you for this and for the many other tutorials that you have provided, I just wanted to ask if you can update this tutorial to use the new features of eclipse that assist in converting an existing project into a Maven project.

caroline
Guest
caroline

Where is the guide? it seems that this article is uncomplete?! i don’t get it. I have a web project on my eclipse, and i moved all my sources to the src/main/java, but still get the web project view!!! how can i have the maven view???

Oscar Blass
Guest
Oscar Blass

Thank you so much. I muddled through this and have my project working in Maven and Eclipse. Thank you very much for sharing this information.

Eric Martin
Guest
Eric Martin

Where do I copy my existing Tomcat .jsp, and .html files in Maven?
Thanks,
Eric

Yogi
Guest
Yogi

If there is a tool to generate the dependency configuration unit?

dli7mar
Guest
dli7mar

When the war file is ready, how do I deploy it to tomcat? how do I create the application folder under tomcat/webapps?
Thanks.

aaaa
Guest
aaaa

just put war there

Jaimoto
Guest
Jaimoto

Genio!

Thanks for the tutorial, really helpful !

mostafa
Guest
mostafa
please tell me what is the problem ? the following is an exception when i run a war file in weblogic: Error 500–Internal Server Error org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [ch.orange.pna.csr.web.MonitoringController] for bean with name ‘MonitoringController’ defined in ServletContext resource [/WEB-INF/CSR-servlet.xml]; nested exception is java.lang.ClassNotFoundException: Class bytes found but defineClass()failed for: ‘ch.orange.pna.csr.web.MonitoringController’ at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1141) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:524) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1177) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:758) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:422) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:306) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:251) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:220) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:112) at javax.servlet.GenericServlet.init(GenericServlet.java:258) at weblogic.servlet.internal.ServletStubImpl$ServletInitAction.run(ServletStubImpl.java:1094) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) at weblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java:970) at weblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.java:949) at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:888) at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:598) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:406) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:348) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6981) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) at… Read more »
Amol Ghotankar
Guest
Amol Ghotankar
Hi, Thanks for the post and I have been your fan and following you all time. I have a web project which is now grown a lot big and hence there is a need to convert it into maven and use the modules/trunk type architecture using which I can separate out the modules and keep then separately. Any guide to create the same? May be part-2 of this series? Problem is I have around 10 modules in the project and each module has set of dto’s, dao’s & services. Now I want to migrate to repository based maven structure which… Read more »
swetha naik
Guest
swetha naik

I have a already built maven project, now I want to add few more files to utilise their functionality. I tried to include those folders in the path required, but it shows error when I do a maven build. What are changes I need to do to add them, so that I can use them in the project.

Mark
Guest
Mark

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.

Fred Bricon
Guest
Fred Bricon

There is such a tool now, check out JBoss Tools 4.0.0(-Beta) from http://marketplace.eclipse.org/node/420896#.UJjaIcXA_Mo. You’ll be able to identify, select, adjust the scope, convert of your dependencies : http://docs.jboss.org/tools/whatsnew/maven/maven-news-4.0.0.Beta1.html

A screencast showcasing this feature : http://bit.ly/QUCyRj

trackback
Creating a quick maven war project | Nguni Phakela's Blog

[…] 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/ […]

trackback
Convert Java web project to Maven based project - Maven Tutorial

[…] 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 : […]

trackback
Maven Tutorials | Tutorials

[…] Convert Java web project to Maven project Here’s an article to guide how to convert an existing Java project to Maven style project. […]

trackback
Java bookmark links, Dec 2009 – Week 1 | bookmark-link

[…] 1) 2 Dec 09 – Article about How to convert Java web project to Maven project […]

trackback
Tomcat deploy Maven project web.xml to a wrong folder in Eclipse | Maven

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

Alpin
Guest
Alpin

hi. im need this article.. i think some part of this guide is missing…