3

I'm migrating from Apache Ant + Apache Ivy to Apache Maven for the lifecycle management of a new project.

I've never used Maven for official releases, so I'm a total newbie on this.

Currently I have installed and configured Maven 3 and the M2Eclipse Plugin, and I've created a new Struts2 WAR project with The Blank Convention Archetype (struts2-archetype-convention), project that I'm able to deploy to JBoss 7.

After reading tons of articles and StackOverflow answers I've figured out that the first rule of Maven is: one project, one artifact;

Then, to work with an EAR I need three projects: EAR, WAR, EJB; but this answer suggests that I need 4 projects, not three: one EAR, one WAR, one EJB, and one PARENT. I thought that the EJB would be the parent... so the first question is:

  • which is the right way ?

And now that I've a working Struts2 WAR, the second question is:

  • Which is the best (cleanest, commonly used) way to include my existing WAR in an EAR project (or in a PARENT project, if needed) ?

Creating it manually ? Generating some other ear artifact or Java-EE-webapp artifacts, and then add the dependencies ? Any example of an hypothetical POM.xml needed would be greatly appreciated.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • Just to make it clear: archetypes is just a templates for projects. You can create maven project without it, all you need is `pom.xml`. – Aleksandr M Oct 01 '13 at 21:44
  • Absolutely, I'll edit to make it clear – Andrea Ligios Oct 02 '13 at 08:20
  • IMO separate parent is better. You can manage all required dependencies and configurations in there and leave them out of your other projects. And you can use your EJB project somewhere else. Also see this link: http://books.sonatype.com/mvnref-book/reference/pom-relationships-sect-pom-best-practice.html#pom-relationships-sect-multi-vs-inherit. – Aleksandr M Oct 02 '13 at 11:45
  • Thanks @AleksandrM for answering the first point (I've edited the question to remove the noise, while you was commenting). I'm gonna read that article now. – Andrea Ligios Oct 02 '13 at 11:50

1 Answers1

2

I ended up using:

  1. JBoss Java EE 6 WebApp Archetype to generate the WebApp, composed by four projects: Parent, EAR, EJB, WAR:

    mvn archetype:generate \
            -DarchetypeArtifactId=jboss-javaee6-webapp-archetype \
            -DarchetypeGroupId=org.jboss.spec.archetypes \
            -DarchetypeVersion=7.0.2.CR2
    
  2. Struts2 Blank Convention Archetype to generate the WAR:

    mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \
            -DartifactId=myWebApp \
            -DarchetypeGroupId=org.apache.struts \
            -DarchetypeArtifactId=struts2-archetype-convention \
            -DarchetypeVersion=<CURRENT_STRUTS_VERSION> \
            -DremoteRepositories=http://struts.apache.org
    
  3. Then I manually replaced the WAR generated by JBoss with the WAR generated by Struts2.

I guess it is the cleanest way.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243