Maven is a build tool for Java based web apps – plain and simple.

Before learning about Maven I did my builds using Ant. And when it came to building webapps, I was always frustrated about getting things in source control in such a way that all of the developers could build their apps no matter what IDE they were using. For example, you get some developers using Eclipse and others using Net Beans, and the different IDEs wants things set up their own way.

By using Maven (instead of ANT or batch files), you do your builds independent of the IDE using the command line; nevertheless, the build can still be done using the IDE if you choose to do so. However, by using the command line, you ensure that your IDE isn’t playing tricks on you.

Follow the instructions of the documentation for getting Maven installed on your development machine.

Next run the command from the command line:

mvn archetype:generate -Dfilter=org.apache:struts

This alone will result in the generation of a basic Hello World generic struts application to get you started.

You will be able to further build out your application using the directory structure following the instructions on Maven Directory Structure.

/
+- src/
|  +- main/
|  |  +- java/
|  |  |  +- ...
|  |  +- resources/
|  |     +- ...
|  +- test/
|  |  +- java/
|  |  |  +- ...
|  |  +- resources/
|  |     +- ...
|  +- site/
|     +- xdoc/
|        +- ...
+- target/
|  +- ...
+- project.xml
+- README.txt
+- LICENSE.txt

Directory 1:
src -> main -> java
In this directory, place your java class files. In the basic struts template, you will have the example package stored here.

src -> main -> java -> example -> ExampleSupport.java
src -> main -> java -> example -> Login.java
src -> main -> java -> example -> HelloWorlds.java

Directory 2:
src -> main -> resources
In this directory, place your resource files.

src -> main -> resources -> example.xml
src -> main -> resources -> struts.xml
src -> main -> resources -> NOTICE.txt
src -> main -> resources -> LICENSE.txt
src -> main -> resources -> example -> Login-validation.xml
src -> main -> resources -> example -> package.properties
src -> main -> resources -> example -> package_es.properties

Directory 3
src -> main -> webapp
Location for the jsp files

src -> main -> webapp -> example -> HelloWorld.jsp
src -> main -> webapp -> example -> Login.jsp
src -> main -> webapp -> example -> Menu.jsp
src -> main -> webapp -> example -> Missing.jsp
src -> main -> webapp -> example -> Register.jsp
src -> main -> webapp -> example -> Welcome.jsp
src -> main -> webapp -> WEB-INF -> web.xml

Directory 4
Now set up a place for your unit tests. This is actually not part of the basic struts application but could be if test cases are added by the developers.

src -> test -> java -> example -> ExampleSupportTest.java
src -> test -> java -> example -> LoginTest.java
src -> test -> java -> example -> HelloWorldsTest.java

POM File
A lot of additional configurations are placed in the POM file. Follow the Maven documentation for specifics. However, for beginners, you will want to use Eclipse or some other tool to build your base pom.xml file held at the root to the app. I added the jar files used by struts in the maven dependencies sections and it automatically filled out the appropriate sections of the POM.xml file.

My beginning POM file looks like this.

  4.0.0
  trisummit
  trisummit
  0.0.1-SNAPSHOT
war
  trisummit

    Jira
    http://applications.trisummit.net/jira/

    Bamboo
    http://applications.trisummit.net/bamboo/

   Brian Nettles
      svn://trisummit.net:3690/trisummit/

    Trismmit Technologies
    http://trisummit.net

          org.apache.maven.plugins
         maven-compiler-plugin
         2.1
                  1.6 1.6 

      com.opensymphony
      xwork-core
      2.1.6
      jar
      compile

      ognl
      ognl
      2.7.3
      jar
      compile

      freemarker
      freemarker
      2.3.9
      compile

                junit
                junit
                4.8.1

      commons-fileupload
      commons-fileupload
      1.2.1

      commons-io
      commons-io
      20030203.000550

      org.apache.struts
      struts2-core
      2.1.8.1

        ip-97-74-115-5.ip.secureserver.net
        ip-97-74-115-5.ip.secureserver.net-releases
        http://applications.trisummit.net/artifactory/libs-releases-local

Now open the command line and from the root of the application, type:

mvn compile

This will compile your application

Now type

mvn war:war

This will create your war file complete with the jar files included and place it in the target directory. Your jar files are managed from the repositories and not stored in your source control.

Now go deploy your war file on Tomcat.