How to create a Maven archetype web application for Eclipse?

I have a working or basically working POM that retrieves everything and exactly the JARs that interest me to write the Facelets application. I am using m2eclipse. When I import a new application created by Maven, it happens clean and more or less, as expected, however this does not seem like a dynamic web project, because when trying to launch it it does not offer Run As โ†’ Run on Server option.

I studied other Eclipse projects created by Maven that work (but are not configured using the JAR combination that I want) in the sense that they can be run on the server. For example, this one works, but it did not get the JAR I want:

mvn archetype: generate-DarchetypeArtifactId = maven-archetype-webapp \ -DgroupId = package-name -DartifactId = project-name

I need to create an arbitrary archetype of artifactId to emulate ... - DarchetypeArtifactId = maven-archetype-webapp ... I see in the command above and, if so, how?

Or is it just a file system function created by this archetype? I see that the project that I created (webapp1) ...

  webapp1
 | - src
 |  `- main
 |  | - java
 |  | - resources
 |  `- webapp
 |  `- WEB-INF
 `- target
     `- classes`

... has different content than the one generated with maven-archetype-webapp, but I don't know how to force mvn eclipse: clear eclipse: eclipse to generate this (or what Eclipse says is a web application and it must be configured for Run As -> Run on Server).

  simpleWeb
 | - src
 |  `- main
 |  | - java
 |  |  `- com
 |  |  `- mytutorial
 |  | - resources
 |  |  `- com
 |  |  `- mytutorial
 |  `- webapp
 |  | - META-INF
 |  | - pages
 |  `- WEB-INF
 `- target
     | - classes
     |  `- com
     |  `- mytutorial
     | - maven-archiver
     | - META-INF
     |  `- maven
     |  `- com.mytutorial
     |  `- simpleWeb
     | - pages
     | - simpleWeb
     |  | - META-INF
     |  | - pages
     |  `- WEB-INF
     |  | - classes
     |  |  `- com
     |  |  `- mytutorial
     |  `- lib
     | - surefire
     | - test-classes
     `- WEB-INF
         | - classes
         |  `- com
         |  `- mytutorial
         `- lib

The professor thanks anyone who can lead me on the path of enlightenment.

Russ

PS Here is my 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.etretatlogiciels.webapp1</groupId> <artifactId>webapp1</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>webapp1 Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <commons-beanutils-version> 1.8.3 </commons-beanutils-version> <commons-codec-version> 1.4 </commons-codec-version> <commons-collections-version> 3.2.1 </commons-collections-version> <commons-digester-version> 2.1 </commons-digester-version> <commons-discovery-version> 0.4 </commons-discovery-version> <commons-logging-version> 1.1.1 </commons-logging-version> <jsf-facelets-version> 1.1.15 </jsf-facelets-version> <myfaces-version> 2.0.4 </myfaces-version> <richfaces-version> 3.3.3.Final </richfaces-version> </properties> <pluginRepositories> <pluginRepository> <id>jboss-public-repository-group</id> <name>JBoss Public Maven Repository Group</name> <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url> <layout>default</layout> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </snapshots> </pluginRepository> </pluginRepositories> <dependencies> <!-- Apache Commons --> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>${commons-beanutils-version}</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>${commons-codec-version}</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>${commons-collections-version}</version> <optional>true</optional> </dependency> <dependency> <groupId>commons-digester</groupId> <artifactId>commons-digester</artifactId> <version>${commons-digester-version}</version> </dependency> <dependency> <groupId>commons-discovery</groupId> <artifactId>commons-discovery</artifactId> <version>${commons-discovery-version}</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>${commons-logging-version}</version> </dependency> <!-- Facelets --> <dependency> <groupId>com.sun.facelets</groupId> <artifactId>jsf-facelets</artifactId> <version>${jsf-facelets-version}</version> </dependency> <!-- MyFaces --> <dependency> <groupId>org.apache.myfaces.core</groupId> <artifactId>myfaces-api</artifactId> <version>${myfaces-version}</version> </dependency> <dependency> <groupId>org.apache.myfaces.core</groupId> <artifactId>myfaces-impl</artifactId> <version>${myfaces-version}</version> </dependency> <!-- RichFaces --> <dependency> <groupId>org.richfaces.framework</groupId> <artifactId>richfaces-api-jsf2</artifactId> <version>${richfaces-version}</version> </dependency> <dependency> <groupId>org.richfaces.framework</groupId> <artifactId>richfaces-impl-jsf2</artifactId> <version>${richfaces-version}</version> </dependency> <dependency> <groupId>org.richfaces.framework</groupId> <artifactId>richfaces-ui-jsf2</artifactId> <version>${richfaces-version}</version> </dependency> <!-- JUnit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <finalName>webapp1</finalName> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.java</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.0</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build> <profiles> <profile> <id>richfaces</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>maven2.repository</id> <name>Repository for Maven by Maven</name> <url>http://repo2.maven.org/maven2</url> <layout>default</layout> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> </repository> <repository> <id>maven2-repository.dev.java.net</id> <name>Java.net Repository for Maven</name> <url>http://download.java.net/maven/1</url> <layout>legacy</layout> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> </repository> <repository> <id>JBoss Repository Old</id> <name>Repository for Maven by JBoss</name> <url>http://repository.jboss.org/maven2</url> <layout>default</layout> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> </repository> <repository> <id>JBoss Repository Nexus</id> <name>Repository for Maven by JBoss</name> <url>http://repository.jboss.org/nexus/content/groups/public-jboss</url> <layout>default</layout> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> </repository> </repositories> </profile> </profiles> </project> 
+6
eclipse maven-2 maven-archetype
source share
3 answers

I had exactly the same problem. None of the existing archetypes matched my needs. If I created (from eclipse) a project from a user archetype, it would not become a dynamic web project. If you run mvn -Dwtpversion = 2.0 eclipse: eclipse again adds all kinds of things you don't need. So after the investigation, I eventually found out that I was denying a โ€œdynamic web projectโ€. This is a bunch of directories and files in a .settings directory and entries in a .project.

So you need to do the following:
1.) create an empty (weak) dynamic web project from eclipse.
2.) Without adding any files or any other changes, check the following files created by eclipse on the file system (relative to the project directory):
.project
.settings / org.eclipse.jdt.core.prefs
.settings / org.eclipse.wst.common.project.facet.core.prefs.xml
.settings / org.eclipse.wst.jsdt.ui.superType.name
.settings / org.eclipse.jst.jsp.core.prefs
.settings / org.eclipse.wst.common.project.facet.core.xml
.settings / org.eclipse.wst.common.component
.settings / org.eclipse.wst.jsdt.ui.superType.container

3.) Copy these files to the resource archetype directory for your custom archetype
4.) Edit and summarize the copied files (replacing the names of real projects with $ {artifactId}, etc.


5.) In the archetype-metadata.xml file add:

 <fileSet encoding="UTF-8" filtered="true"> <directory></directory> <includes> <include>.project</include> </includes> </fileSet> <fileSet encoding="UTF-8" filtered="true"> <directory>.settings</directory> </fileSet> 

Without this, maven will not download files starting with ". *"

6.) Voila !. Install and deploy your archetype and try again. It worked for me.

+7
source share

how easy is it to configure the maven-eclipse plugin in your archetype /pom.xml file?

 <build> <finalName>archetype-javaee5-webapp</finalName> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <version>2.9</version> <configuration> <wtpversion>2.0</wtpversion> </configuration> </plugin> </plugins> </pluginManagement> </build> 

this will create a web project in eclipse

+7
source share

To create a dynamic web project for Eclipse, you need to do the following:

1) create a project using something like:

mvn archetype: generate> optional arguments such as -Dfilter = webapp-j2ee <

This will help you create your maven project interactively, and you wonโ€™t have to enter parameters for artifactId, groupId, etc.

Note. It may still not be a dynamic web project, in my case it never ... (I think it mainly depends on the archetype-artifactId that you used, and I did not find the one that will create the Dynamic Web module for a basic j2ee application that will only use jsp, a servlet and nothing else)

2) Now, to generate the project file for eclipse, use the following command:

mvn -Dwtpversion = 2.0 eclipse: eclipse

This will create a project file that will have the necessary facet of the project. Therefore, when you import it into your Eclipse development environment, it will be a โ€œDynamic Web Moduleโ€.

Note. Now, if you are looking for a specific version of the "Dynamic Web Module", you need to configure your POM. The version depends on the following tag in the assembly tag:

 <code> <build> ...... <plugins> ........ <plugin> <groupId> org.apache.maven.plugins </groupId> <artifactId> maven-compiler-plugin </artifactId> <version> 2.3.2 </version> <configuration> <source> 1.6 </source> <target> 1.6 </target> </configuration> </plugin> ......... </plugins> ....... </build> </code> 

Now, if the source and target are set to 1.6 (as in this case), then the dynamic web module 2.5 will be selected. Otherwise, it will be 2.4 for the compiler-plugin 1.4, etc.

+1
source share

All Articles