Create simple struts2 project using maven commands


Let's see how we can create a very simple project structure for Struts2 application using maven in command prompt or terminal.

Note: Below is an example demonstrated on Mac OS X using terminal

Lets first set the JAVA_HOME and PATH for maven ( my version is maven 3.3.3)

localhost:~ code2care$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/
localhost:~ code2care$ export PATH=/Users/code2care/Setups/apache-maven-3.3.3/bin:$PATH

Now let's run the maven archetype: generate a command to display the project stub :

localhost:~ code2care$ mvn archetype:generate
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> maven-archetype-plugin:2.4:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] 
[INFO] <<< maven-archetype-plugin:2.4:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO] 
[INFO] --- maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)


9: remote -> br.com.address.archetypes:struts2-archetype (an archetype web 3.0 + struts2 (bootstrap + jquery) + JPA 2.1 with struts2 login system)
167: remote -> com.jgeppert.struts2.jquery:struts2-jquery-archetype-base (This Archetype provides a Webapp Configuration ready for the Struts2 jQuery Plugin.)
168: remote -> com.jgeppert.struts2.jquery:struts2-jquery-archetype-mobile (This Archetype provides a Webapp Configuration ready for the Struts2 jQuery Mobile Plugin.)
169: remote -> com.jgeppert.struts2.jquery:struts2-jquery-bootstrap-archetype-grid (This Archetype provides a Webapp Configuration ready for the Struts2 jQuery Grid Plugin and the Struts2
743: remote -> org.apache.struts:struts2-archetype-angularjs (-)
744: remote -> org.apache.struts:struts2-archetype-blank (-)
745: remote -> org.apache.struts:struts2-archetype-convention (-)
746: remote -> org.apache.struts:struts2-archetype-dbportlet (-)
747: remote -> org.apache.struts:struts2-archetype-plugin (-)
748: remote -> org.apache.struts:struts2-archetype-portlet (-)
749: remote -> org.apache.struts:struts2-archetype-starter (-)

I have just listed out a few struts2 projects that may be useful for us

Lets select number 744 : org.apache.struts:struts2-archetype-blank

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 644: 744

Select the struts 2 version that you want : I have selected 25 i.e. version 2.3.24

Choose org.apache.struts:struts2-archetype-blank version:

1: 2.2.1
2: 2.2.1.1
3: 2.2.3
4: 2.2.3.1
5: 2.3.3
6: 2.3.4
7: 2.3.4.1
8: 2.3.7
9: 2.3.8
10: 2.3.12
11: 2.3.14
12: 2.3.14.1
13: 2.3.14.2
14: 2.3.14.3
15: 2.3.15
16: 2.3.15.1
17: 2.3.15.2
18: 2.3.15.3
19: 2.3.16
20: 2.3.16.1
21: 2.3.16.2
22: 2.3.16.3
23: 2.3.20
24: 2.3.20.1
25: 2.3.24
26: 2.5-BETA1
Choose a number: 26: 25
Downloading: https://repo.maven.apache.org/maven2/org/apache/struts/struts2-archetype-blank/2.3.24/struts2-archetype-blank-2.3.24.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/struts/struts2-archetype-blank/2.3.24/struts2-archetype-blank-2.3.24.jar (39 KB at 13.2 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/struts/struts2-archetype-blank/2.3.24/struts2-archetype-blank-2.3.24.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/struts/struts2-archetype-blank/2.3.24/struts2-archetype-blank-2.3.24.pom (3 KB at 4.0 KB/sec)
Define the properties : groupId, artifactId, version and package,
Define value for property 'groupId': : org.code2care.struts2
Define value for property 'artifactId': : HelloStruts2
Define value for property 'version':  1.0-SNAPSHOT: : 
Define value for property 'package':  org.code2care.struts2: : 
Confirm properties configuration:
groupId: org.code2care.struts2
artifactId: HelloStruts2
version: 1.0-SNAPSHOT
package: org.code2care.struts2
 Y: : Y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: struts2-archetype-blank:2.3.24
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.code2care.struts2
[INFO] Parameter: artifactId, Value: HelloStruts2
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: org.code2care.struts2
[INFO] Parameter: packageInPathFormat, Value: org/code2care/struts2
[INFO] Parameter: package, Value: org.code2care.struts2
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: org.code2care.struts2
[INFO] Parameter: artifactId, Value: HelloStruts2
[INFO] project created from Archetype in dir: /Users/code2care/HelloStruts2
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:37 min
[INFO] Finished at: 2015-09-15T11:47:15+05:30
[INFO] Final Memory: 13M/98M
[INFO] ------------------------------------------------------------------------
localhost:~ code2care$ 

That's it! You should see BUILD SUCCESS and the location where the project HelloStruts2 just above that info line.