Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Maven Archetype after a project is created in Eclipse?

I've created a Maven project with maven-archetype-quickstart.

I've started coding and now I want to change the archetype to maven-archetype-webapp in order to make it a dynamic web project.

How do I achieve this?

like image 656
Harshal Kshatriya Avatar asked Apr 22 '13 07:04

Harshal Kshatriya


People also ask

How do I change the archetype in Eclipse?

Right-click the project > Properties > Project Facets. Select Convert to faceted form...

How do you update archetypes?

If you want to change the archetype's files, you will need to contact the author of the archetype and suggest a change. If the archetype is from github.com, for example, you could fork the archetype, make the change, and request a pull. You could also submit a bug/issue report.

What should be the archetype for Maven project in Eclipse?

If you want a web application, use maven-archetype-webapp, or if you want a simple application use maven-archetype-quickstart. They are useful because you will be able to expand them with no problem. Note that this is in the Eclipse plugin by default (at least it is today).


2 Answers

Archetypes are just used to create a project (ie initialize configuration, source folders, ...) and are not used after that. So if you want to change your project nature you've to do it "by hand".

It seems that in your case, you just have to change in pom.xml, the package type to war and to proceed a "Maven update project" in your IDE so maven plugin will update configuration.

like image 104
yodamad Avatar answered Sep 30 '22 14:09

yodamad


I recently googled and got stumbled upon this post. I have got a way to generate the web.xml and the directory structure for a web application using Eclipse IDE. Before I share that, let's clarify the Eclipse I am using (this feature may not be there in case you are using any older version).

enter image description here

I assume you created the Maven Project with maven-archetype-quickstart as posted by OP. It is basically a jar application. We want to change this to a web application. Here is the process:

  1. Right-click the project > Properties > Project Facets
  2. Select Convert to faceted form...
  3. Tic the Dynamic Web Module and Java boxes. You may want to select the version you need, make sure these are compatible. I selected version 3.0 for Dynamic Web Module (the servlet spec) and Java 1.8.

enter image description here

  1. Now click Apply and Close. This will generate many things in your project.
  2. Now switch to Web perspective if you're not already in. You can do that by following: Window > Perspective > Open Perspective > Other > Web
  3. Now you will be able to see what changes we made to project structure in step 4. It has created the directory structure required for web applications. But still web.xml file is not yet generated. We will do it next.
  4. Right-click on Deployment Descriptor : <your project name> > Generate Deployment Descriptor Stub. It will generate the web.xml file.

enter image description here

  1. Finally change the packaging in pom.xml from jar to war:<packaging>war</packaging>
  2. Now you are ready to go. Since I was working with spring-boot and it requires the webapp folder instead of WebContent, I manually renamed it and moved it inside src\main and then added the webapp as a source folder.

So basically, we have to do this all manually. I just made Eclipse do little bit of work here.

like image 29
tusar Avatar answered Sep 30 '22 15:09

tusar