Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a web application project to maven project?

Tags:

maven

I am having a exsting dynamic web project. Now I am planning to maven to this project. May I know how can I acheive that?

like image 543
Venkata Ramireddy CH Avatar asked Jun 06 '14 10:06

Venkata Ramireddy CH


People also ask

Is Maven used for web application?

You will create a Maven build definition file that's called a pom. xml file, which stands for Project Object Model, and use it to build your web application. You will then create a simple, automated test and configure Maven to automatically run the test.

How do I run a Maven web application?

Create Web Application To create a simple java web application, we will use maven-archetype-webapp plugin. So, let's open the command console, go to the C:\MVN directory and execute the following mvn command. Sr.No. contains src folder and pom.


2 Answers

First of all it's not good to change web project type once you have created one it's bad practice. You should either decide before you begin your project to do it as dynamic web project or with maven. When you do this it would help you to avoid lots of errors when converting project type to another and also when you use IDE to create for example Maven project it would build the base automatically based on your project configurations.

However it is possible to convert dynamic web project to Maven. Here's what you need to do:

If you are using Eclipse, you can simply do this by right-clicking your mouse on your project and choose from menu Configure -> Convert to Maven Project. If this doesn't work then you have to do it with hard way, which is:

  1. Create Maven project folder structure

    • You need to move all exiting java source files to \src\main\java
    • Move web.xml to \src\main\webapp\WEB-INF
    • Create pom.xml file and put it in your project root folder. (If for some reason you don't have above folders then you need to create them accordingly)
  2. Configure project details in pom.xml file. Here's an example of pom.xml file that has project details.

  3. Configure dependency libraries. This means that you need to add all libraries you use in your web project as dependencies in pom.xml.

  4. Compile your project with mvn compile command. To run this command you need to go to your project folder and then run it there. If you are using Windows then you must do this in command prompt, if you are using Linux, use Terminal.

  5. (Optional) If you want to make your project support Eclipse IDE then run following command mvn eclipse:eclipse -Dwtpversion=2.0.

  6. Now you need to generate .war file for purpose of deployment. To do this you must go again to your project folder using command prompt/Terminal and run following maven command mvn war:war. This will generate WAR file in your project target folder.

like image 187
Amir Al Avatar answered Oct 07 '22 09:10

Amir Al


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.
like image 35
Santosh Bansode Avatar answered Oct 07 '22 09:10

Santosh Bansode